mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-06-08 20:58:34 +00:00
CompressorWorker: isolate thread body inside static function
this prevents accidental access to shared properties, which would cost performance.
This commit is contained in:
parent
135fe149f0
commit
366968722f
@ -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){
|
||||
|
Loading…
x
Reference in New Issue
Block a user