mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-06-07 04:17:07 +00:00
AsyncWorker: added removeFromThreadStore()
and use it instead of overwriting with null things, which still occupies memory
This commit is contained in:
parent
ee787974f2
commit
b331f8e1c9
@ -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");
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
*
|
||||
|
@ -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]);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user