CommonThreadPartsTrait: add common implementation of quit()

there's no need for the worker specialization here (isShutdown and shutdown are aliased to isJoined and join respectively), and the unstacking is not really desirable either as we previously learned with AsyncPool.
This commit is contained in:
Dylan K. Taylor 2023-12-21 12:56:51 +00:00
parent 03619ebca9
commit b69843a8bd
No known key found for this signature in database
GPG Key ID: 8927471A91CAFD3D
3 changed files with 14 additions and 31 deletions

View File

@ -120,6 +120,20 @@ trait CommonThreadPartsTrait{
$this->isKilled = true;
}
/**
* Stops the thread using the best way possible. Try to stop it yourself before calling this.
*/
public function quit() : void{
$this->isKilled = true;
if(!$this->isJoined()){
$this->notify();
$this->join();
}
ThreadManager::getInstance()->remove($this);
}
/**
* Called by set_exception_handler() when an uncaught exception is thrown.
*/

View File

@ -37,18 +37,4 @@ use pocketmine\scheduler\AsyncTask;
*/
abstract class Thread extends NativeThread{
use CommonThreadPartsTrait;
/**
* Stops the thread using the best way possible. Try to stop it yourself before calling this.
*/
public function quit() : void{
$this->isKilled = true;
if(!$this->isJoined()){
$this->notify();
$this->join();
}
ThreadManager::getInstance()->remove($this);
}
}

View File

@ -38,21 +38,4 @@ use pocketmine\scheduler\AsyncTask;
*/
abstract class Worker extends NativeWorker{
use CommonThreadPartsTrait;
/**
* Stops the thread using the best way possible. Try to stop it yourself before calling this.
*/
public function quit() : void{
$this->isKilled = true;
if(!$this->isShutdown()){
$this->synchronized(function() : void{
while($this->unstack() !== null);
});
$this->notify();
$this->shutdown();
}
ThreadManager::getInstance()->remove($this);
}
}