diff --git a/src/scheduler/AsyncTask.php b/src/scheduler/AsyncTask.php index 754eaf65d..9d69bda5b 100644 --- a/src/scheduler/AsyncTask.php +++ b/src/scheduler/AsyncTask.php @@ -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>|null + * @var mixed[][] object hash => mixed data + * @phpstan-var array> * - * 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|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)]); } /**