From c684f99cc4663b4fe1ce16bb79efa0dad4d105d8 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Thu, 26 Jul 2018 14:17:01 +0100 Subject: [PATCH 1/2] Clean up Thread/Worker quit() --- src/pocketmine/Thread.php | 7 ++----- src/pocketmine/Worker.php | 10 ++-------- 2 files changed, 4 insertions(+), 13 deletions(-) diff --git a/src/pocketmine/Thread.php b/src/pocketmine/Thread.php index 2c539b90e..617aa8f53 100644 --- a/src/pocketmine/Thread.php +++ b/src/pocketmine/Thread.php @@ -83,12 +83,9 @@ abstract class Thread extends \Thread{ public function quit(){ $this->isKilled = true; - $this->notify(); - if(!$this->isJoined()){ - if(!$this->isTerminated()){ - $this->join(); - } + $this->notify(); + $this->join(); } ThreadManager::getInstance()->remove($this); diff --git a/src/pocketmine/Worker.php b/src/pocketmine/Worker.php index f79f502d8..a6255b81b 100644 --- a/src/pocketmine/Worker.php +++ b/src/pocketmine/Worker.php @@ -83,16 +83,10 @@ abstract class Worker extends \Worker{ public function quit(){ $this->isKilled = true; - $this->notify(); - if($this->isRunning()){ - $this->shutdown(); + while($this->unstack() !== null); $this->notify(); - $this->unstack(); - }elseif(!$this->isJoined()){ - if(!$this->isTerminated()){ - $this->join(); - } + $this->shutdown(); } ThreadManager::getInstance()->remove($this); From 1b053c7928d4372d9b1d64b5a33705531059d4da Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Thu, 26 Jul 2018 14:20:55 +0100 Subject: [PATCH 2/2] Clean up pointless checks in Thread/Worker --- src/pocketmine/Thread.php | 10 +++------- src/pocketmine/Worker.php | 10 +++------- 2 files changed, 6 insertions(+), 14 deletions(-) diff --git a/src/pocketmine/Thread.php b/src/pocketmine/Thread.php index 617aa8f53..a3d7f41be 100644 --- a/src/pocketmine/Thread.php +++ b/src/pocketmine/Thread.php @@ -67,14 +67,10 @@ abstract class Thread extends \Thread{ public function start(?int $options = \PTHREADS_INHERIT_ALL){ ThreadManager::getInstance()->add($this); - if(!$this->isRunning() and !$this->isJoined() and !$this->isTerminated()){ - if($this->getClassLoader() === null){ - $this->setClassLoader(); - } - return parent::start($options); + if($this->getClassLoader() === null){ + $this->setClassLoader(); } - - return false; + return parent::start($options); } /** diff --git a/src/pocketmine/Worker.php b/src/pocketmine/Worker.php index a6255b81b..fffa93248 100644 --- a/src/pocketmine/Worker.php +++ b/src/pocketmine/Worker.php @@ -67,14 +67,10 @@ abstract class Worker extends \Worker{ public function start(?int $options = \PTHREADS_INHERIT_ALL){ ThreadManager::getInstance()->add($this); - if(!$this->isRunning() and !$this->isJoined() and !$this->isTerminated()){ - if($this->getClassLoader() === null){ - $this->setClassLoader(); - } - return parent::start($options); + if($this->getClassLoader() === null){ + $this->setClassLoader(); } - - return false; + return parent::start($options); } /**