CompressorWorker: isolate thread body inside static function

this prevents accidental access to shared properties, which would cost performance.
This commit is contained in:
Dylan K. Taylor 2023-11-13 10:50:33 +00:00
parent 135fe149f0
commit 366968722f
No known key found for this signature in database
GPG Key ID: 8927471A91CAFD3D

View File

@ -26,6 +26,7 @@ namespace pocketmine\network\mcpe\compression;
use pmmp\thread\ThreadSafeArray;
use pocketmine\snooze\SleeperHandler;
use pocketmine\snooze\SleeperHandlerEntry;
use pocketmine\snooze\SleeperNotifier;
use pocketmine\thread\Thread;
use pocketmine\utils\AssumptionFailedError;
use function count;
@ -82,10 +83,14 @@ final class CompressorWorker{
public function onRun() : void{
/** @var Compressor $compressor */
$compressor = unserialize($this->compressor);
$inChannel = $this->inChannel;
$outChannel = $this->outChannel;
$sleeperNotifier = $this->sleeperEntry->createNotifier();
self::thread($this->inChannel, $compressor, $this->outChannel, $this->sleeperEntry->createNotifier());
}
/**
* @phpstan-param ThreadSafeArray<int, string|null> $inChannel
* @phpstan-param ThreadSafeArray<int, string> $outChannel
*/
private static function thread(ThreadSafeArray $inChannel, Compressor $compressor, ThreadSafeArray $outChannel, SleeperNotifier $sleeperNotifier) : void{
$shutdown = false;
while(!$shutdown){