mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-05-15 18:29:46 +00:00
Use time_sleep_until() instead of usleep(), improved thread kill
This commit is contained in:
parent
d830386786
commit
0ddf396b08
@ -466,20 +466,10 @@ namespace pocketmine {
|
|||||||
|
|
||||||
foreach(ThreadManager::getInstance()->getAll() as $id => $thread){
|
foreach(ThreadManager::getInstance()->getAll() as $id => $thread){
|
||||||
if($thread->isRunning()){
|
if($thread->isRunning()){
|
||||||
$logger->debug("Stopping " . (new \ReflectionClass($thread))->getShortName() . " thread");
|
$logger->debug("Killing " . (new \ReflectionClass($thread))->getShortName() . " thread");
|
||||||
if($thread instanceof Thread){
|
$thread->kill();
|
||||||
$thread->kill();
|
sleep(1);
|
||||||
sleep(1);
|
$thread->detach();
|
||||||
if($thread->isRunning()){
|
|
||||||
$thread->detach();
|
|
||||||
}
|
|
||||||
}elseif($thread instanceof Worker){
|
|
||||||
$thread->kill();
|
|
||||||
sleep(1);
|
|
||||||
if($thread->isRunning()){
|
|
||||||
$thread->detach();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}elseif(!$thread->isJoined()){
|
}elseif(!$thread->isJoined()){
|
||||||
if(!$thread->isTerminated()){
|
if(!$thread->isTerminated()){
|
||||||
$logger->debug("Joining " . (new \ReflectionClass($thread))->getShortName() . " thread");
|
$logger->debug("Joining " . (new \ReflectionClass($thread))->getShortName() . " thread");
|
||||||
@ -487,6 +477,7 @@ namespace pocketmine {
|
|||||||
}else{
|
}else{
|
||||||
$logger->debug("Killing " . (new \ReflectionClass($thread))->getShortName() . " thread");
|
$logger->debug("Killing " . (new \ReflectionClass($thread))->getShortName() . " thread");
|
||||||
$thread->kill();
|
$thread->kill();
|
||||||
|
$thread->detach();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2186,7 +2186,7 @@ class Server{
|
|||||||
private function tickProcessor(){
|
private function tickProcessor(){
|
||||||
while($this->isRunning){
|
while($this->isRunning){
|
||||||
$this->tick();
|
$this->tick();
|
||||||
usleep((int) max(1, ($this->nextTick - microtime(true)) * 1000000 - 2000));
|
time_sleep_until($this->nextTick - 0.001);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user