mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-06-17 00:44:08 +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();
|
Timings::$schedulerAsyncTimer->startTiming();
|
||||||
|
|
||||||
foreach($this->tasks as $task){
|
foreach($this->tasks as $task){
|
||||||
if(!$task->isGarbage() and $task->progressUpdates !== null){
|
if(!$task->isGarbage()){
|
||||||
if($task->progressUpdates->count() !== 0){
|
$task->checkProgressUpdates($this->server);
|
||||||
$progress = $task->progressUpdates->shift();
|
|
||||||
$task->onProgressUpdate($this->server, $progress);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if($task->isGarbage() and !$task->isRunning() and !$task->isCrashed()){
|
if($task->isGarbage() and !$task->isRunning() and !$task->isCrashed()){
|
||||||
if(!$task->hasCancelledRun()){
|
if(!$task->hasCancelledRun()){
|
||||||
|
@ -35,7 +35,7 @@ abstract class AsyncTask extends Collectable{
|
|||||||
public $worker = null;
|
public $worker = null;
|
||||||
|
|
||||||
/** @var \Threaded */
|
/** @var \Threaded */
|
||||||
public $progressUpdates = null;
|
public $progressUpdates;
|
||||||
|
|
||||||
private $result = null;
|
private $result = null;
|
||||||
private $serialized = false;
|
private $serialized = false;
|
||||||
@ -69,7 +69,6 @@ abstract class AsyncTask extends Collectable{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function run(){
|
public function run(){
|
||||||
$this->progressUpdates = new \Threaded; // Do not move this to __construct for backwards compatibility.
|
|
||||||
$this->result = null;
|
$this->result = null;
|
||||||
|
|
||||||
if($this->cancelRun !== true){
|
if($this->cancelRun !== true){
|
||||||
@ -182,6 +181,18 @@ abstract class AsyncTask extends Collectable{
|
|||||||
$this->progressUpdates[] = $progress;
|
$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.
|
* Called from the main thread after {@link AsyncTask#publishProgress} is called.
|
||||||
* All {@link AsyncTask#publishProgress} calls should result in {@link AsyncTask#onProgressUpdate} calls before
|
* All {@link AsyncTask#publishProgress} calls should result in {@link AsyncTask#onProgressUpdate} calls before
|
||||||
|
@ -78,6 +78,7 @@ class ServerScheduler{
|
|||||||
public function scheduleAsyncTask(AsyncTask $task){
|
public function scheduleAsyncTask(AsyncTask $task){
|
||||||
$id = $this->nextId();
|
$id = $this->nextId();
|
||||||
$task->setTaskId($id);
|
$task->setTaskId($id);
|
||||||
|
$task->progressUpdates = new \Threaded;
|
||||||
$this->asyncPool->submitTask($task);
|
$this->asyncPool->submitTask($task);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user