Fixed pthreads crashes with progressUpdates

This commit is contained in:
SOFe
2016-11-12 18:30:55 +08:00
parent 7861822a0f
commit 8404ce88bd
3 changed files with 16 additions and 7 deletions

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