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.
This commit is contained in:
Dylan K. Taylor 2023-12-21 12:44:03 +00:00
parent fd1bc1b845
commit 03619ebca9
No known key found for this signature in database
GPG Key ID: 8927471A91CAFD3D
3 changed files with 10 additions and 21 deletions

View File

@ -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();

View File

@ -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.
*/

View File

@ -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.
*/