diff --git a/src/pocketmine/PocketMine.php b/src/pocketmine/PocketMine.php index 4fc5345d0..c5bc3daaa 100644 --- a/src/pocketmine/PocketMine.php +++ b/src/pocketmine/PocketMine.php @@ -473,8 +473,6 @@ namespace pocketmine { $logger->shutdown(); $logger->join(); - - $killer->kill(); echo Terminal::$FORMAT_RESET . "\n"; diff --git a/src/pocketmine/Server.php b/src/pocketmine/Server.php index 1ecff73c9..786d69036 100644 --- a/src/pocketmine/Server.php +++ b/src/pocketmine/Server.php @@ -1970,7 +1970,7 @@ class Server{ $this->getLogger()->debug("Closing console"); $this->console->shutdown(); - $this->console->kill(); + $this->console->notify(); $this->getLogger()->debug("Stopping network interfaces"); foreach($this->network->getInterfaces() as $interface){ diff --git a/src/pocketmine/Thread.php b/src/pocketmine/Thread.php index d7a33f757..57e7726d9 100644 --- a/src/pocketmine/Thread.php +++ b/src/pocketmine/Thread.php @@ -28,6 +28,7 @@ abstract class Thread extends \Thread{ /** @var \ClassLoader */ protected $classLoader; + protected $isKilled = false; public function getClassLoader(){ return $this->classLoader; @@ -68,16 +69,14 @@ abstract class Thread extends \Thread{ * Stops the thread using the best way possible. Try to stop it yourself before calling this. */ public function quit(){ - if($this->isRunning()){ - $this->kill(); - }elseif(!$this->isJoined()){ + $this->isKilled = true; + + $this->notify(); + + if(!$this->isJoined()){ if(!$this->isTerminated()){ $this->join(); - }else{ - $this->kill(); } - }else{ - $this->kill(); } ThreadManager::getInstance()->remove($this); @@ -86,4 +85,4 @@ abstract class Thread extends \Thread{ public function getThreadName(){ return (new \ReflectionClass($this))->getShortName(); } -} \ No newline at end of file +} diff --git a/src/pocketmine/ThreadManager.php b/src/pocketmine/ThreadManager.php index b79a78c7d..27851a098 100644 --- a/src/pocketmine/ThreadManager.php +++ b/src/pocketmine/ThreadManager.php @@ -42,7 +42,7 @@ class ThreadManager extends \Volatile{ */ public function add($thread){ if($thread instanceof Thread or $thread instanceof Worker){ - $this->{$thread->getThreadId()} = $thread; + $this->{spl_object_hash($thread)} = $thread; } } @@ -51,7 +51,7 @@ class ThreadManager extends \Volatile{ */ public function remove($thread){ if($thread instanceof Thread or $thread instanceof Worker){ - unset($this->{$thread->getThreadId()}); + unset($this->{spl_object_hash($thread)}); } } diff --git a/src/pocketmine/Worker.php b/src/pocketmine/Worker.php index 547e50963..0d2f2c098 100644 --- a/src/pocketmine/Worker.php +++ b/src/pocketmine/Worker.php @@ -28,6 +28,8 @@ abstract class Worker extends \Worker{ /** @var \ClassLoader */ protected $classLoader; + + protected $isKilled = false; public function getClassLoader(){ return $this->classLoader; @@ -68,17 +70,18 @@ abstract class Worker extends \Worker{ * Stops the thread using the best way possible. Try to stop it yourself before calling this. */ public function quit(){ + $this->isKilled = true; + + $this->notify(); + if($this->isRunning()){ + $this->shutdown(); + $this->notify(); $this->unstack(); - $this->kill(); }elseif(!$this->isJoined()){ if(!$this->isTerminated()){ $this->join(); - }else{ - $this->kill(); } - }else{ - $this->kill(); } ThreadManager::getInstance()->remove($this); @@ -87,4 +90,4 @@ abstract class Worker extends \Worker{ public function getThreadName(){ return (new \ReflectionClass($this))->getShortName(); } -} \ No newline at end of file +} diff --git a/src/pocketmine/plugin/PluginLogger.php b/src/pocketmine/plugin/PluginLogger.php index 1a1dc5457..12cf47dfc 100644 --- a/src/pocketmine/plugin/PluginLogger.php +++ b/src/pocketmine/plugin/PluginLogger.php @@ -87,10 +87,14 @@ class PluginLogger implements \AttachableLogger{ $this->log(LogLevel::DEBUG, $message); } + public function logException(\Throwable $e, $trace = null){ + Server::getInstance()->getLogger()->logException($e, $trace); + } + public function log($level, $message){ Server::getInstance()->getLogger()->log($level, $this->pluginName . $message); foreach($this->attachments as $attachment){ $attachment->log($level, $message); } } -} \ No newline at end of file +} diff --git a/src/pocketmine/scheduler/AsyncPool.php b/src/pocketmine/scheduler/AsyncPool.php index 50022ec97..dafb9f48b 100644 --- a/src/pocketmine/scheduler/AsyncPool.php +++ b/src/pocketmine/scheduler/AsyncPool.php @@ -47,7 +47,7 @@ class AsyncPool{ for($i = 0; $i < $this->size; ++$i){ $this->workerUsage[$i] = 0; - $this->workers[$i] = new AsyncWorker($this->server->getLogger(), $i); + $this->workers[$i] = new AsyncWorker($this->server->getLogger(), $i + 1); $this->workers[$i]->setClassLoader($this->server->getLoader()); $this->workers[$i]->start(); } @@ -62,7 +62,7 @@ class AsyncPool{ if($newSize > $this->size){ for($i = $this->size; $i < $newSize; ++$i){ $this->workerUsage[$i] = 0; - $this->workers[$i] = new AsyncWorker($this->server->getLogger(), $i); + $this->workers[$i] = new AsyncWorker($this->server->getLogger(), $i + 1); $this->workers[$i]->setClassLoader($this->server->getLoader()); $this->workers[$i]->start(); } diff --git a/src/pocketmine/utils/ServerKiller.php b/src/pocketmine/utils/ServerKiller.php index 34333f463..8bc2521d0 100644 --- a/src/pocketmine/utils/ServerKiller.php +++ b/src/pocketmine/utils/ServerKiller.php @@ -32,11 +32,14 @@ class ServerKiller extends Thread{ } public function run(){ + $start = time() + 1; $this->synchronized(function(){ $this->wait($this->time * 1000000); }); - echo "\nTook too long to stop, server was killed forcefully!\n"; - @\pocketmine\kill(getmypid()); + if(time() - $start >= $this->time){ + echo "\nTook too long to stop, server was killed forcefully!\n"; + @\pocketmine\kill(getmypid()); + } } public function getThreadName(){ diff --git a/src/raklib b/src/raklib index f6f207b9e..a5cca45a9 160000 --- a/src/raklib +++ b/src/raklib @@ -1 +1 @@ -Subproject commit f6f207b9e47dc6fdb23b9e39dfcbabb545be9cd0 +Subproject commit a5cca45a922ca193a616069f885866efc7158c67 diff --git a/src/spl b/src/spl index 3cd1f13c5..6edaf9802 160000 --- a/src/spl +++ b/src/spl @@ -1 +1 @@ -Subproject commit 3cd1f13c5d4937a5de1978d1950589082df760d2 +Subproject commit 6edaf9802cbada5e7638ceadfe042be9921376d8