38 private static array $store = [];
43 public function __construct(
46 private int $memoryLimit,
51 if(self::$notifier !==
null){
52 return self::$notifier;
57 public static function maybeCollectCycles() :
void{
58 if(self::$cycleGcManager ===
null){
61 self::$cycleGcManager->maybeCollectCycles();
64 protected function onRun() :
void{
65 \GlobalLogger::set($this->logger);
67 if($this->memoryLimit > 0){
68 ini_set(
'memory_limit', $this->memoryLimit .
'M');
69 $this->logger->debug(
"Set memory limit to " . $this->memoryLimit .
" MB");
71 ini_set(
'memory_limit',
'-1');
72 $this->logger->debug(
"No memory limit set");
75 self::$notifier = $this->sleeperEntry->createNotifier();
84 public function getThreadName() :
string{
85 return "AsyncWorker#" . $this->id;
88 public function getAsyncWorkerId() :
int{
99 if(NativeThread::getCurrentThread() !== $this){
100 throw new \LogicException(
"Thread-local data can only be stored in the thread context");
102 self::$store[$identifier] = $value;
116 if(NativeThread::getCurrentThread() !== $this){
117 throw new \LogicException(
"Thread-local data can only be fetched in the thread context");
119 return self::$store[$identifier] ??
null;
128 if(NativeThread::getCurrentThread() !== $this){
129 throw new \LogicException(
"Thread-local data can only be removed in the thread context");
131 unset(self::$store[$identifier]);