mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-06-18 09:24:05 +00:00
Prevent undefined behaviour when accessing async worker thread-store from outside the worker itself
This commit is contained in:
parent
a0f3c03b50
commit
24677e1d79
@ -90,6 +90,9 @@ class AsyncWorker extends Worker{
|
|||||||
* @param mixed $value
|
* @param mixed $value
|
||||||
*/
|
*/
|
||||||
public function saveToThreadStore(string $identifier, $value) : void{
|
public function saveToThreadStore(string $identifier, $value) : void{
|
||||||
|
if(\Thread::getCurrentThread() !== $this){
|
||||||
|
throw new \InvalidStateException("Thread-local data can only be stored in the thread context");
|
||||||
|
}
|
||||||
self::$store[$identifier] = $value;
|
self::$store[$identifier] = $value;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -105,6 +108,9 @@ class AsyncWorker extends Worker{
|
|||||||
* @return mixed
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
public function getFromThreadStore(string $identifier){
|
public function getFromThreadStore(string $identifier){
|
||||||
|
if(\Thread::getCurrentThread() !== $this){
|
||||||
|
throw new \InvalidStateException("Thread-local data can only be fetched in the thread context");
|
||||||
|
}
|
||||||
return self::$store[$identifier] ?? null;
|
return self::$store[$identifier] ?? null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -114,6 +120,9 @@ class AsyncWorker extends Worker{
|
|||||||
* @param string $identifier
|
* @param string $identifier
|
||||||
*/
|
*/
|
||||||
public function removeFromThreadStore(string $identifier) : void{
|
public function removeFromThreadStore(string $identifier) : void{
|
||||||
|
if(\Thread::getCurrentThread() !== $this){
|
||||||
|
throw new \InvalidStateException("Thread-local data can only be removed in the thread context");
|
||||||
|
}
|
||||||
unset(self::$store[$identifier]);
|
unset(self::$store[$identifier]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user