diff --git a/src/pocketmine/Server.php b/src/pocketmine/Server.php index e45ff806f..f127ce761 100644 --- a/src/pocketmine/Server.php +++ b/src/pocketmine/Server.php @@ -1322,7 +1322,6 @@ class Server{ $this->banByIP = new BanList($this->dataPath . "banned-ips.txt"); $this->banByIP->load(); - $this->scheduler = new ServerScheduler(); $this->console = new CommandReader(); $version = new VersionString($this->getPocketMineVersion()); @@ -1359,6 +1358,10 @@ class Server{ "auto-save" => true, )); + ServerScheduler::$WORKERS = $this->getProperty("settings.async-workers", ServerScheduler::$WORKERS); + + $this->scheduler = new ServerScheduler(); + if($this->getConfigBoolean("enable-rcon", false) === true){ $this->rcon = new RCON($this->getConfigString("rcon.password", ""), $this->getConfigInt("rcon.port", $this->getPort()), ($ip = $this->getIp()) != "" ? $ip : "0.0.0.0", $this->getConfigInt("rcon.threads", 1), $this->getConfigInt("rcon.clients-per-thread", 50)); } @@ -1679,7 +1682,7 @@ class Server{ $this->logger->info("Default game type: " . self::getGamemodeString($this->getGamemode())); //TODO: string name $this->logger->info("Done (" . round(microtime(true) - \pocketmine\START_TIME, 3) . 's)! For help, type "help" or "?"'); - $this->scheduler->scheduleAsyncTask(new ExampleTask()); + if(Utils::getOS() === "win"){ //Workaround less usleep() waste $this->tickProcessorWindows(); }else{ diff --git a/src/pocketmine/resources/pocketmine.yml b/src/pocketmine/resources/pocketmine.yml index 05470cae7..c42d196ed 100644 --- a/src/pocketmine/resources/pocketmine.yml +++ b/src/pocketmine/resources/pocketmine.yml @@ -7,6 +7,7 @@ settings: advanced-cache: false upnp-forwarding: false send-usage: true + async-workers: 3 debug: #If > 1, it will show debug messages in the console diff --git a/src/pocketmine/scheduler/AsyncWorker.php b/src/pocketmine/scheduler/AsyncWorker.php index 8d4c91578..ccef45b2d 100644 --- a/src/pocketmine/scheduler/AsyncWorker.php +++ b/src/pocketmine/scheduler/AsyncWorker.php @@ -24,13 +24,10 @@ namespace pocketmine\scheduler; class AsyncWorker extends \Worker{ public $path; - public function __construct(){ + public function start($options = PTHREADS_INHERIT_ALL){ $this->path = \pocketmine\PATH; - return parent::start(PTHREADS_INHERIT_ALL & ~PTHREADS_INHERIT_CLASSES); - } - - public function start(){ + return parent::start($options & ~PTHREADS_INHERIT_CLASSES); } public function run(){ diff --git a/src/pocketmine/scheduler/ServerScheduler.php b/src/pocketmine/scheduler/ServerScheduler.php index fc70c8f3f..bd3dfdafe 100644 --- a/src/pocketmine/scheduler/ServerScheduler.php +++ b/src/pocketmine/scheduler/ServerScheduler.php @@ -28,7 +28,7 @@ use pocketmine\plugin\Plugin; use pocketmine\utils\ReversePriorityQueue; class ServerScheduler{ - protected static $WORKERS = 3; + public static $WORKERS = 3; /** * @var ReversePriorityQueue */