From 0ddf396b086e5f6f17e68486fd0149b7500c14bb Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Sun, 3 May 2015 23:17:39 +0200 Subject: [PATCH] Use time_sleep_until() instead of usleep(), improved thread kill --- src/pocketmine/PocketMine.php | 19 +++++-------------- src/pocketmine/Server.php | 2 +- 2 files changed, 6 insertions(+), 15 deletions(-) diff --git a/src/pocketmine/PocketMine.php b/src/pocketmine/PocketMine.php index 6f728b682..af7791648 100644 --- a/src/pocketmine/PocketMine.php +++ b/src/pocketmine/PocketMine.php @@ -466,20 +466,10 @@ namespace pocketmine { foreach(ThreadManager::getInstance()->getAll() as $id => $thread){ if($thread->isRunning()){ - $logger->debug("Stopping " . (new \ReflectionClass($thread))->getShortName() . " thread"); - if($thread instanceof Thread){ - $thread->kill(); - sleep(1); - if($thread->isRunning()){ - $thread->detach(); - } - }elseif($thread instanceof Worker){ - $thread->kill(); - sleep(1); - if($thread->isRunning()){ - $thread->detach(); - } - } + $logger->debug("Killing " . (new \ReflectionClass($thread))->getShortName() . " thread"); + $thread->kill(); + sleep(1); + $thread->detach(); }elseif(!$thread->isJoined()){ if(!$thread->isTerminated()){ $logger->debug("Joining " . (new \ReflectionClass($thread))->getShortName() . " thread"); @@ -487,6 +477,7 @@ namespace pocketmine { }else{ $logger->debug("Killing " . (new \ReflectionClass($thread))->getShortName() . " thread"); $thread->kill(); + $thread->detach(); } } } diff --git a/src/pocketmine/Server.php b/src/pocketmine/Server.php index 82f7d204d..4f0b1b8c8 100644 --- a/src/pocketmine/Server.php +++ b/src/pocketmine/Server.php @@ -2186,7 +2186,7 @@ class Server{ private function tickProcessor(){ while($this->isRunning){ $this->tick(); - usleep((int) max(1, ($this->nextTick - microtime(true)) * 1000000 - 2000)); + time_sleep_until($this->nextTick - 0.001); } }