mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-06-06 20:07:09 +00:00
AsyncWorker: clean up nonsensical sleeper notifier handling code
This commit is contained in:
parent
bf99917f2a
commit
c05116849a
@ -24,12 +24,10 @@ declare(strict_types=1);
|
||||
namespace pocketmine\scheduler;
|
||||
|
||||
use pmmp\thread\Runnable;
|
||||
use pmmp\thread\Thread as NativeThread;
|
||||
use pmmp\thread\ThreadSafe;
|
||||
use pmmp\thread\ThreadSafeArray;
|
||||
use pocketmine\thread\NonThreadSafeValue;
|
||||
use function array_key_exists;
|
||||
use function assert;
|
||||
use function igbinary_serialize;
|
||||
use function igbinary_unserialize;
|
||||
use function is_null;
|
||||
@ -83,9 +81,7 @@ abstract class AsyncTask extends Runnable{
|
||||
$this->onRun();
|
||||
|
||||
$this->finished = true;
|
||||
$worker = NativeThread::getCurrentThread();
|
||||
assert($worker instanceof AsyncWorker);
|
||||
$worker->getNotifier()->wakeupSleeper();
|
||||
AsyncWorker::getNotifier()->wakeupSleeper();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -36,7 +36,7 @@ class AsyncWorker extends Worker{
|
||||
/** @var mixed[] */
|
||||
private static array $store = [];
|
||||
|
||||
private const TLS_KEY_NOTIFIER = self::class . "::notifier";
|
||||
private static ?SleeperNotifier $notifier = null;
|
||||
|
||||
public function __construct(
|
||||
private ThreadSafeLogger $logger,
|
||||
@ -45,12 +45,11 @@ class AsyncWorker extends Worker{
|
||||
private SleeperHandlerEntry $sleeperEntry
|
||||
){}
|
||||
|
||||
public function getNotifier() : SleeperNotifier{
|
||||
$notifier = $this->getFromThreadStore(self::TLS_KEY_NOTIFIER);
|
||||
if(!$notifier instanceof SleeperNotifier){
|
||||
throw new AssumptionFailedError("SleeperNotifier not found in thread-local storage");
|
||||
public static function getNotifier() : SleeperNotifier{
|
||||
if(self::$notifier !== null){
|
||||
return self::$notifier;
|
||||
}
|
||||
return $notifier;
|
||||
throw new AssumptionFailedError("SleeperNotifier not found in thread-local storage");
|
||||
}
|
||||
|
||||
protected function onRun() : void{
|
||||
@ -66,7 +65,7 @@ class AsyncWorker extends Worker{
|
||||
$this->logger->debug("No memory limit set");
|
||||
}
|
||||
|
||||
$this->saveToThreadStore(self::TLS_KEY_NOTIFIER, $this->sleeperEntry->createNotifier());
|
||||
self::$notifier = $this->sleeperEntry->createNotifier();
|
||||
}
|
||||
|
||||
public function getLogger() : ThreadSafeLogger{
|
||||
|
Loading…
x
Reference in New Issue
Block a user