mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-04-22 08:44:01 +00:00
ServerKiller: fixed start/stop race condition
in some cases the main thread was trying to signal the server killer to stop before it was even started due to limited resources available for scheduling.
This commit is contained in:
parent
753ed3801d
commit
126a97b405
@ -29,6 +29,9 @@ class ServerKiller extends Thread{
|
||||
|
||||
public $time;
|
||||
|
||||
/** @var bool */
|
||||
private $stopped = false;
|
||||
|
||||
public function __construct($time = 15){
|
||||
$this->time = $time;
|
||||
}
|
||||
@ -37,7 +40,9 @@ class ServerKiller extends Thread{
|
||||
$this->registerClassLoader();
|
||||
$start = time();
|
||||
$this->synchronized(function(){
|
||||
$this->wait($this->time * 1000000);
|
||||
if(!$this->stopped){
|
||||
$this->wait($this->time * 1000000);
|
||||
}
|
||||
});
|
||||
if(time() - $start >= $this->time){
|
||||
echo "\nTook too long to stop, server was killed forcefully!\n";
|
||||
@ -45,6 +50,14 @@ class ServerKiller extends Thread{
|
||||
}
|
||||
}
|
||||
|
||||
public function quit() : void{
|
||||
$this->synchronized(function() : void{
|
||||
$this->stopped = true;
|
||||
$this->notify();
|
||||
});
|
||||
parent::quit();
|
||||
}
|
||||
|
||||
public function getThreadName() : string{
|
||||
return "Server Killer";
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user