mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-06-28 06:09:57 +00:00
Be sure that AsyncTask finish executing, fixes #2931
This commit is contained in:
parent
7ad98d4659
commit
fba12f2a13
@ -1994,25 +1994,32 @@ class Server{
|
|||||||
UPnP::RemovePortForward($this->getPort());
|
UPnP::RemovePortForward($this->getPort());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$this->getLogger()->debug("Disabling all plugins");
|
||||||
$this->pluginManager->disablePlugins();
|
$this->pluginManager->disablePlugins();
|
||||||
|
|
||||||
foreach($this->players as $player){
|
foreach($this->players as $player){
|
||||||
$player->close($player->getLeaveMessage(), $this->getProperty("settings.shutdown-message", "Server closed"));
|
$player->close($player->getLeaveMessage(), $this->getProperty("settings.shutdown-message", "Server closed"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$this->getLogger()->debug("Unloading all levels");
|
||||||
foreach($this->getLevels() as $level){
|
foreach($this->getLevels() as $level){
|
||||||
$this->unloadLevel($level, true);
|
$this->unloadLevel($level, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$this->getLogger()->debug("Removing event handlers");
|
||||||
HandlerList::unregisterAll();
|
HandlerList::unregisterAll();
|
||||||
|
|
||||||
|
$this->getLogger()->debug("Stopping all tasks");
|
||||||
$this->scheduler->cancelAllTasks();
|
$this->scheduler->cancelAllTasks();
|
||||||
$this->scheduler->mainThreadHeartbeat(PHP_INT_MAX);
|
$this->scheduler->mainThreadHeartbeat(PHP_INT_MAX);
|
||||||
|
|
||||||
|
$this->getLogger()->debug("Saving properties");
|
||||||
$this->properties->save();
|
$this->properties->save();
|
||||||
|
|
||||||
|
$this->getLogger()->debug("Closing console");
|
||||||
$this->console->kill();
|
$this->console->kill();
|
||||||
|
|
||||||
|
$this->getLogger()->debug("Stopping network interfaces");
|
||||||
foreach($this->network->getInterfaces() as $interface){
|
foreach($this->network->getInterfaces() as $interface){
|
||||||
$interface->shutdown();
|
$interface->shutdown();
|
||||||
$this->network->unregisterInterface($interface);
|
$this->network->unregisterInterface($interface);
|
||||||
|
@ -106,6 +106,9 @@ class AsyncPool{
|
|||||||
|
|
||||||
private function removeTask(AsyncTask $task){
|
private function removeTask(AsyncTask $task){
|
||||||
if(isset($this->taskWorkers[$task->getTaskId()])){
|
if(isset($this->taskWorkers[$task->getTaskId()])){
|
||||||
|
if($task->isRunning() or !$task->isGarbage()){
|
||||||
|
return;
|
||||||
|
}
|
||||||
$this->workers[$w = $this->taskWorkers[$task->getTaskId()]]->unstack($task);
|
$this->workers[$w = $this->taskWorkers[$task->getTaskId()]]->unstack($task);
|
||||||
$this->workerUsage[$w]--;
|
$this->workerUsage[$w]--;
|
||||||
}
|
}
|
||||||
@ -119,9 +122,15 @@ class AsyncPool{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function removeTasks(){
|
public function removeTasks(){
|
||||||
foreach($this->tasks as $task){
|
do{
|
||||||
$this->removeTask($task);
|
foreach($this->tasks as $task){
|
||||||
}
|
$this->removeTask($task);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(count($this->tasks) > 0){
|
||||||
|
usleep(25000);
|
||||||
|
}
|
||||||
|
}while(count($this->tasks) > 0);
|
||||||
|
|
||||||
for($i = 0; $i < $this->size; ++$i){
|
for($i = 0; $i < $this->size; ++$i){
|
||||||
$this->workerUsage[$i] = 0;
|
$this->workerUsage[$i] = 0;
|
||||||
@ -135,7 +144,7 @@ class AsyncPool{
|
|||||||
Timings::$schedulerAsyncTimer->startTiming();
|
Timings::$schedulerAsyncTimer->startTiming();
|
||||||
|
|
||||||
foreach($this->tasks as $task){
|
foreach($this->tasks as $task){
|
||||||
if($task->isGarbage()){
|
if($task->isGarbage() and !$task->isRunning()){
|
||||||
|
|
||||||
$task->onCompletion($this->server);
|
$task->onCompletion($this->server);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user