mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-04-21 08:17:34 +00:00
AsyncTask: remove ArrayObject hack
this is no longer a concern with pmmpthread + PHP 8.1 and up. The behaviour that caused statics to be inherited was caused by bugs in PHP 8.0 and below, which have now been fixed.
This commit is contained in:
parent
0240d35c05
commit
36f52f1ade
@ -61,12 +61,12 @@ use function spl_object_id;
|
||||
*/
|
||||
abstract class AsyncTask extends Runnable{
|
||||
/**
|
||||
* @var \ArrayObject|mixed[]|null object hash => mixed data
|
||||
* @phpstan-var \ArrayObject<int, array<string, mixed>>|null
|
||||
* @var mixed[][] object hash => mixed data
|
||||
* @phpstan-var array<int, array<string, mixed>>
|
||||
*
|
||||
* Used to store objects which are only needed on one thread and should not be serialized.
|
||||
* Used to store thread-local data to be used by onCompletion().
|
||||
*/
|
||||
private static ?\ArrayObject $threadLocalStorage = null;
|
||||
private static array $threadLocalStorage = [];
|
||||
|
||||
/** @phpstan-var ThreadSafeArray<int, string>|null */
|
||||
private ?ThreadSafeArray $progressUpdates = null;
|
||||
@ -212,15 +212,6 @@ abstract class AsyncTask extends Runnable{
|
||||
* from.
|
||||
*/
|
||||
protected function storeLocal(string $key, mixed $complexData) : void{
|
||||
if(self::$threadLocalStorage === null){
|
||||
/*
|
||||
* It's necessary to use an object (not array) here because pthreads is stupid. Non-default array statics
|
||||
* will be inherited when task classes are copied to the worker thread, which would cause unwanted
|
||||
* inheritance of primitive thread-locals, which we really don't want for various reasons.
|
||||
* It won't try to inherit objects though, so this is the easiest solution.
|
||||
*/
|
||||
self::$threadLocalStorage = new \ArrayObject();
|
||||
}
|
||||
self::$threadLocalStorage[spl_object_id($this)][$key] = $complexData;
|
||||
}
|
||||
|
||||
@ -236,7 +227,7 @@ abstract class AsyncTask extends Runnable{
|
||||
*/
|
||||
protected function fetchLocal(string $key){
|
||||
$id = spl_object_id($this);
|
||||
if(self::$threadLocalStorage === null || !isset(self::$threadLocalStorage[$id][$key])){
|
||||
if(!isset(self::$threadLocalStorage[$id][$key])){
|
||||
throw new \InvalidArgumentException("No matching thread-local data found on this thread");
|
||||
}
|
||||
|
||||
@ -245,12 +236,7 @@ abstract class AsyncTask extends Runnable{
|
||||
|
||||
final public function __destruct(){
|
||||
$this->reallyDestruct();
|
||||
if(self::$threadLocalStorage !== null && isset(self::$threadLocalStorage[$h = spl_object_id($this)])){
|
||||
unset(self::$threadLocalStorage[$h]);
|
||||
if(self::$threadLocalStorage->count() === 0){
|
||||
self::$threadLocalStorage = null;
|
||||
}
|
||||
}
|
||||
unset(self::$threadLocalStorage[spl_object_id($this)]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user