AsyncWorker: added removeFromThreadStore()

and use it instead of overwriting with null things, which still occupies memory
This commit is contained in:
Dylan K. Taylor 2018-06-07 10:12:50 +01:00
parent ee787974f2
commit b331f8e1c9
3 changed files with 23 additions and 2 deletions

View File

@ -35,7 +35,7 @@ class GeneratorUnregisterTask extends AsyncTask{
}
public function onRun(){
$this->saveToThreadStore("generation.level{$this->levelId}.manager", null);
$this->saveToThreadStore("generation.level{$this->levelId}.generator", null);
$this->removeFromThreadStore("generation.level{$this->levelId}.manager");
$this->removeFromThreadStore("generation.level{$this->levelId}.generator");
}
}

View File

@ -151,6 +151,18 @@ abstract class AsyncTask extends Collectable{
$this->worker->saveToThreadStore($identifier, $value);
}
/**
* @see AsyncWorker::removeFromThreadStore()
*
* @param string $identifier
*/
public function removeFromThreadStore(string $identifier) : void{
if($this->worker === null or $this->isGarbage()){
throw new \BadMethodCallException("Objects can only be removed from AsyncWorker thread-local storage during task execution");
}
$this->worker->removeFromThreadStore($identifier);
}
/**
* Actions to execute when run
*

View File

@ -98,4 +98,13 @@ class AsyncWorker extends Worker{
public function getFromThreadStore(string $identifier){
return self::$store[$identifier] ?? null;
}
/**
* Removes previously-stored mixed data from the worker's thread-local object store.
*
* @param string $identifier
*/
public function removeFromThreadStore(string $identifier) : void{
unset(self::$store[$identifier]);
}
}