Shut down mapgen threads before other shutdown tasks (#6689)

Solves some issues with ModStorage functionality in mapgen threads
that occurred when mapgen threads continued to run after the main
server thread had stopped. Also shuts down mapgen threads before
shutdown callbacks are called.
This commit is contained in:
raymoo 2017-12-03 01:28:35 -08:00 committed by SmallJoker
parent 7d9dbbbf3c
commit 48ebbf0fc6

@ -335,9 +335,6 @@ Server::~Server()
{ {
MutexAutoLock envlock(m_env_mutex); MutexAutoLock envlock(m_env_mutex);
// Execute script shutdown hooks
m_script->on_shutdown();
infostream << "Server: Saving players" << std::endl; infostream << "Server: Saving players" << std::endl;
m_env->saveLoadedPlayers(); m_env->saveLoadedPlayers();
@ -353,6 +350,20 @@ Server::~Server()
} }
m_env->kickAllPlayers(SERVER_ACCESSDENIED_SHUTDOWN, m_env->kickAllPlayers(SERVER_ACCESSDENIED_SHUTDOWN,
kick_msg, reconnect); kick_msg, reconnect);
}
// Do this before stopping the server in case mapgen callbacks need to access
// server-controlled resources (like ModStorages). Also do them before
// shutdown callbacks since they may modify state that is finalized in a
// callback.
m_emerge->stopThreads();
{
MutexAutoLock envlock(m_env_mutex);
// Execute script shutdown hooks
infostream << "Executing shutdown hooks" << std::endl;
m_script->on_shutdown();
infostream << "Server: Saving environment metadata" << std::endl; infostream << "Server: Saving environment metadata" << std::endl;
m_env->saveMeta(); m_env->saveMeta();
@ -362,10 +373,6 @@ Server::~Server()
stop(); stop();
delete m_thread; delete m_thread;
// stop all emerge threads before deleting players that may have
// requested blocks to be emerged
m_emerge->stopThreads();
// Delete things in the reverse order of creation // Delete things in the reverse order of creation
delete m_emerge; delete m_emerge;
delete m_env; delete m_env;