Fixed pthreads crashes with progressUpdates

This commit is contained in:
SOFe 2016-11-12 18:30:55 +08:00
parent 7861822a0f
commit 8404ce88bd
No known key found for this signature in database
GPG Key ID: A0379676C4D9D5D9
3 changed files with 16 additions and 7 deletions

View File

@ -142,11 +142,8 @@ class AsyncPool{
Timings::$schedulerAsyncTimer->startTiming();
foreach($this->tasks as $task){
if(!$task->isGarbage() and $task->progressUpdates !== null){
if($task->progressUpdates->count() !== 0){
$progress = $task->progressUpdates->shift();
$task->onProgressUpdate($this->server, $progress);
}
if(!$task->isGarbage()){
$task->checkProgressUpdates($this->server);
}
if($task->isGarbage() and !$task->isRunning() and !$task->isCrashed()){
if(!$task->hasCancelledRun()){

View File

@ -35,7 +35,7 @@ abstract class AsyncTask extends Collectable{
public $worker = null;
/** @var \Threaded */
public $progressUpdates = null;
public $progressUpdates;
private $result = null;
private $serialized = false;
@ -69,7 +69,6 @@ abstract class AsyncTask extends Collectable{
}
public function run(){
$this->progressUpdates = new \Threaded; // Do not move this to __construct for backwards compatibility.
$this->result = null;
if($this->cancelRun !== true){
@ -182,6 +181,18 @@ abstract class AsyncTask extends Collectable{
$this->progressUpdates[] = $progress;
}
/**
* @internal Only call from AsyncPool.php on the main thread
*
* @param Server $server
*/
public function checkProgressUpdates(Server $server){
if($this->progressUpdates->count() !== 0){
$progress = $this->progressUpdates->shift();
$this->onProgressUpdate($server, $progress);
}
}
/**
* Called from the main thread after {@link AsyncTask#publishProgress} is called.
* All {@link AsyncTask#publishProgress} calls should result in {@link AsyncTask#onProgressUpdate} calls before

View File

@ -78,6 +78,7 @@ class ServerScheduler{
public function scheduleAsyncTask(AsyncTask $task){
$id = $this->nextId();
$task->setTaskId($id);
$task->progressUpdates = new \Threaded;
$this->asyncPool->submitTask($task);
}