From 03619ebca91387113e749555463c306b33754b0f Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Thu, 21 Dec 2023 12:44:03 +0000 Subject: [PATCH] Thread/Worker: Remove duplicated code Despite the comments, there doesn't seem to be an obvious reason for these to be copy-pasted. Perhaps there was some legacy reason for this with legacy pthreads. In fact, it looks likely that quit() will probably be able to be traitified too. --- src/thread/CommonThreadPartsTrait.php | 10 ++++++++++ src/thread/Thread.php | 10 ---------- src/thread/Worker.php | 11 ----------- 3 files changed, 10 insertions(+), 21 deletions(-) diff --git a/src/thread/CommonThreadPartsTrait.php b/src/thread/CommonThreadPartsTrait.php index de2ecbde8..f01a979b0 100644 --- a/src/thread/CommonThreadPartsTrait.php +++ b/src/thread/CommonThreadPartsTrait.php @@ -23,6 +23,7 @@ declare(strict_types=1); namespace pocketmine\thread; +use pmmp\thread\Thread as NativeThread; use pmmp\thread\ThreadSafeArray; use pocketmine\errorhandler\ErrorToExceptionHandler; use pocketmine\Server; @@ -96,6 +97,15 @@ trait CommonThreadPartsTrait{ public function getCrashInfo() : ?ThreadCrashInfo{ return $this->crashInfo; } + public function start(int $options = NativeThread::INHERIT_NONE) : bool{ + ThreadManager::getInstance()->add($this); + + if($this->getClassLoaders() === null){ + $this->setClassLoaders(); + } + return parent::start($options); + } + final public function run() : void{ error_reporting(-1); $this->registerClassLoaders(); diff --git a/src/thread/Thread.php b/src/thread/Thread.php index 706f96429..2f0204022 100644 --- a/src/thread/Thread.php +++ b/src/thread/Thread.php @@ -38,16 +38,6 @@ use pocketmine\scheduler\AsyncTask; abstract class Thread extends NativeThread{ use CommonThreadPartsTrait; - public function start(int $options = NativeThread::INHERIT_NONE) : bool{ - //this is intentionally not traitified - ThreadManager::getInstance()->add($this); - - if($this->getClassLoaders() === null){ - $this->setClassLoaders(); - } - return parent::start($options); - } - /** * Stops the thread using the best way possible. Try to stop it yourself before calling this. */ diff --git a/src/thread/Worker.php b/src/thread/Worker.php index 3bc5cda97..7d9ca72c3 100644 --- a/src/thread/Worker.php +++ b/src/thread/Worker.php @@ -23,7 +23,6 @@ declare(strict_types=1); namespace pocketmine\thread; -use pmmp\thread\Thread as NativeThread; use pmmp\thread\Worker as NativeWorker; use pocketmine\scheduler\AsyncTask; @@ -40,16 +39,6 @@ use pocketmine\scheduler\AsyncTask; abstract class Worker extends NativeWorker{ use CommonThreadPartsTrait; - public function start(int $options = NativeThread::INHERIT_NONE) : bool{ - //this is intentionally not traitified - ThreadManager::getInstance()->add($this); - - if($this->getClassLoaders() === null){ - $this->setClassLoaders(); - } - return parent::start($options); - } - /** * Stops the thread using the best way possible. Try to stop it yourself before calling this. */