mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-04-22 16:51:42 +00:00
Fixed pthreads crashes with progressUpdates
This commit is contained in:
parent
7861822a0f
commit
8404ce88bd
@ -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()){
|
||||
|
@ -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
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user