mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-07-04 09:10:00 +00:00
RakLib: split PthreadsChannelWriter into two implementations
this gains a very small performance improvement by avoiding unnecessary !== null checks on every packet written in either direction. It's insignificant for sure, but I just found this code in an old stash, so what the heck.
This commit is contained in:
parent
5c609cc1c1
commit
832a156fc7
@ -23,18 +23,12 @@ use raklib\server\ipc\InterThreadChannelWriter;
|
|||||||
final class PthreadsChannelWriter implements InterThreadChannelWriter{
|
final class PthreadsChannelWriter implements InterThreadChannelWriter{
|
||||||
/** @var \Threaded */
|
/** @var \Threaded */
|
||||||
private $buffer;
|
private $buffer;
|
||||||
/** @var SleeperNotifier|null */
|
|
||||||
private $notifier;
|
|
||||||
|
|
||||||
public function __construct(\Threaded $buffer, ?SleeperNotifier $notifier = null){
|
public function __construct(\Threaded $buffer){
|
||||||
$this->buffer = $buffer;
|
$this->buffer = $buffer;
|
||||||
$this->notifier = $notifier;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function write(string $str) : void{
|
public function write(string $str) : void{
|
||||||
$this->buffer[] = $str;
|
$this->buffer[] = $str;
|
||||||
if($this->notifier !== null){
|
|
||||||
$this->notifier->wakeupSleeper();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -153,7 +153,7 @@ class RakLibServer extends Thread{
|
|||||||
$this->maxMtuSize,
|
$this->maxMtuSize,
|
||||||
new SimpleProtocolAcceptor($this->protocolVersion),
|
new SimpleProtocolAcceptor($this->protocolVersion),
|
||||||
new UserToRakLibThreadMessageReceiver(new PthreadsChannelReader($this->mainToThreadBuffer)),
|
new UserToRakLibThreadMessageReceiver(new PthreadsChannelReader($this->mainToThreadBuffer)),
|
||||||
new RakLibToUserThreadMessageSender(new PthreadsChannelWriter($this->threadToMainBuffer, $this->mainThreadNotifier)),
|
new RakLibToUserThreadMessageSender(new SnoozeAwarePthreadsChannelWriter($this->threadToMainBuffer, $this->mainThreadNotifier)),
|
||||||
new ExceptionTraceCleaner($this->mainPath)
|
new ExceptionTraceCleaner($this->mainPath)
|
||||||
);
|
);
|
||||||
$this->synchronized(function() : void{
|
$this->synchronized(function() : void{
|
||||||
|
42
src/network/mcpe/raklib/SnoozeAwarePthreadsChannelWriter.php
Normal file
42
src/network/mcpe/raklib/SnoozeAwarePthreadsChannelWriter.php
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
*
|
||||||
|
* ____ _ _ __ __ _ __ __ ____
|
||||||
|
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||||
|
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
||||||
|
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||||
|
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* @author PocketMine Team
|
||||||
|
* @link http://www.pocketmine.net/
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace pocketmine\network\mcpe\raklib;
|
||||||
|
|
||||||
|
use pocketmine\snooze\SleeperNotifier;
|
||||||
|
use raklib\server\ipc\InterThreadChannelWriter;
|
||||||
|
|
||||||
|
final class SnoozeAwarePthreadsChannelWriter implements InterThreadChannelWriter{
|
||||||
|
private \Threaded $buffer;
|
||||||
|
private SleeperNotifier $notifier;
|
||||||
|
|
||||||
|
public function __construct(\Threaded $buffer, SleeperNotifier $notifier){
|
||||||
|
$this->buffer = $buffer;
|
||||||
|
$this->notifier = $notifier;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function write(string $str) : void{
|
||||||
|
$this->buffer[] = $str;
|
||||||
|
$this->notifier->wakeupSleeper();
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user