Fixed worker pool AsyncTask storage

This commit is contained in:
Shoghi Cervantes 2014-07-05 22:02:14 +02:00
parent 22552cdd72
commit 637d9da5a6
2 changed files with 17 additions and 10 deletions

View File

@ -1349,7 +1349,7 @@ class Level implements ChunkManager, Metadatable{
}else{ }else{
$task = new ChunkRequestTask($this, $x, $z); $task = new ChunkRequestTask($this, $x, $z);
$this->server->getScheduler()->scheduleAsyncTask($task); $this->server->getScheduler()->scheduleAsyncTask($task);
$this->chunkSendTasks[$index] = $task; $this->chunkSendTasks[$index] = true;
} }
} }
} }

View File

@ -45,6 +45,9 @@ class ServerScheduler{
protected $asyncTasks = 0; protected $asyncTasks = 0;
/** @var AsyncTask[] */
protected $asyncTaskStorage = [];
/** @var int */ /** @var int */
private $ids = 1; private $ids = 1;
@ -75,6 +78,7 @@ class ServerScheduler{
*/ */
public function scheduleAsyncTask(AsyncTask $task){ public function scheduleAsyncTask(AsyncTask $task){
$this->asyncPool->submit($task); $this->asyncPool->submit($task);
$this->asyncTaskStorage[spl_object_hash($task)] = $task;
++$this->asyncTasks; ++$this->asyncTasks;
} }
@ -214,16 +218,19 @@ class ServerScheduler{
} }
if($this->asyncTasks > 0){ //Garbage collector if($this->asyncTasks > 0){ //Garbage collector
$this->asyncPool->collect(function (AsyncTask $task){ $this->asyncPool->collect([$this, "collectAsyncTask"]);
}
}
public function collectAsyncTask(AsyncTask $task){
if($task->isFinished() and !$task->isCompleted()){ if($task->isFinished() and !$task->isCompleted()){
--$this->asyncTasks; --$this->asyncTasks;
$task->onCompletion(Server::getInstance()); $task->onCompletion(Server::getInstance());
$task->setCompleted(); $task->setCompleted();
unset($this->asyncTaskStorage[spl_object_hash($task)]);
return true; return true;
} }
return false; return false;
});
}
} }
private function isReady($currentTicks){ private function isReady($currentTicks){