Replace disallowed operators in src/scheduler/

This commit is contained in:
Dylan K. Taylor 2022-01-20 19:20:03 +00:00
parent 03f47d0a78
commit b85fe0e72a
No known key found for this signature in database
GPG Key ID: 8927471A91CAFD3D
4 changed files with 9 additions and 9 deletions

View File

@ -163,7 +163,7 @@ class AsyncPool{
* Submits an AsyncTask to an arbitrary worker. * Submits an AsyncTask to an arbitrary worker.
*/ */
public function submitTaskToWorker(AsyncTask $task, int $worker) : void{ public function submitTaskToWorker(AsyncTask $task, int $worker) : void{
if($worker < 0 or $worker >= $this->size){ if($worker < 0 || $worker >= $this->size){
throw new \InvalidArgumentException("Invalid worker $worker"); throw new \InvalidArgumentException("Invalid worker $worker");
} }
if($task->isSubmitted()){ if($task->isSubmitted()){
@ -197,7 +197,7 @@ class AsyncPool{
} }
} }
} }
if($worker === null or ($minUsage > 0 and count($this->workers) < $this->size)){ if($worker === null || ($minUsage > 0 && count($this->workers) < $this->size)){
//select a worker to start on the fly //select a worker to start on the fly
for($i = 0; $i < $this->size; ++$i){ for($i = 0; $i < $this->size; ++$i){
if(!isset($this->workers[$i])){ if(!isset($this->workers[$i])){
@ -297,7 +297,7 @@ class AsyncPool{
$ret = 0; $ret = 0;
$time = time(); $time = time();
foreach($this->taskQueues as $i => $queue){ foreach($this->taskQueues as $i => $queue){
if((!isset($this->workerLastUsed[$i]) or $this->workerLastUsed[$i] + 300 < $time) and $queue->isEmpty()){ if((!isset($this->workerLastUsed[$i]) || $this->workerLastUsed[$i] + 300 < $time) && $queue->isEmpty()){
$this->workers[$i]->quit(); $this->workers[$i]->quit();
$this->eventLoop->removeNotifier($this->workers[$i]->getNotifier()); $this->eventLoop->removeNotifier($this->workers[$i]->getNotifier());
unset($this->workers[$i], $this->taskQueues[$i], $this->workerLastUsed[$i]); unset($this->workers[$i], $this->taskQueues[$i], $this->workerLastUsed[$i]);

View File

@ -93,7 +93,7 @@ abstract class AsyncTask extends \Threaded{
} }
public function isCrashed() : bool{ public function isCrashed() : bool{
return $this->crashed or $this->isTerminated(); return $this->crashed || $this->isTerminated();
} }
/** /**
@ -101,7 +101,7 @@ abstract class AsyncTask extends \Threaded{
* because it is not true prior to task execution. * because it is not true prior to task execution.
*/ */
public function isFinished() : bool{ public function isFinished() : bool{
return $this->finished or $this->isCrashed(); return $this->finished || $this->isCrashed();
} }
public function hasResult() : bool{ public function hasResult() : bool{
@ -236,7 +236,7 @@ abstract class AsyncTask extends \Threaded{
*/ */
protected function fetchLocal(string $key){ protected function fetchLocal(string $key){
$id = spl_object_id($this); $id = spl_object_id($this);
if(self::$threadLocalStorage === null or !isset(self::$threadLocalStorage[$id][$key])){ if(self::$threadLocalStorage === null || !isset(self::$threadLocalStorage[$id][$key])){
throw new \InvalidArgumentException("No matching thread-local data found on this thread"); throw new \InvalidArgumentException("No matching thread-local data found on this thread");
} }
@ -245,7 +245,7 @@ abstract class AsyncTask extends \Threaded{
final public function __destruct(){ final public function __destruct(){
$this->reallyDestruct(); $this->reallyDestruct();
if(self::$threadLocalStorage !== null and isset(self::$threadLocalStorage[$h = spl_object_id($this)])){ if(self::$threadLocalStorage !== null && isset(self::$threadLocalStorage[$h = spl_object_id($this)])){
unset(self::$threadLocalStorage[$h]); unset(self::$threadLocalStorage[$h]);
if(self::$threadLocalStorage->count() === 0){ if(self::$threadLocalStorage->count() === 0){
self::$threadLocalStorage = null; self::$threadLocalStorage = null;

View File

@ -42,7 +42,7 @@ abstract class Task{
} }
final public function setHandler(?TaskHandler $taskHandler) : void{ final public function setHandler(?TaskHandler $taskHandler) : void{
if($this->taskHandler === null or $taskHandler === null){ if($this->taskHandler === null || $taskHandler === null){
$this->taskHandler = $taskHandler; $this->taskHandler = $taskHandler;
} }
} }

View File

@ -150,6 +150,6 @@ class TaskScheduler{
} }
private function isReady(int $currentTick) : bool{ private function isReady(int $currentTick) : bool{
return !$this->queue->isEmpty() and $this->queue->current()->getNextRun() <= $currentTick; return !$this->queue->isEmpty() && $this->queue->current()->getNextRun() <= $currentTick;
} }
} }