diff options
author | raymoo <raymoo@users.noreply.github.com> | 2017-12-03 01:28:35 -0800 |
---|---|---|
committer | SmallJoker <mk939@ymail.com> | 2018-06-03 17:32:00 +0200 |
commit | 48ebbf0fc642908e26b58fd17f379920dbb1b387 (patch) | |
tree | 78617674446f5478bcedf97a6b1683e5db2016fc | |
parent | 7d9dbbbf3c9102fab35ee4c24a9215d198c3dba0 (diff) | |
download | minetest-48ebbf0fc642908e26b58fd17f379920dbb1b387.tar.gz minetest-48ebbf0fc642908e26b58fd17f379920dbb1b387.tar.bz2 minetest-48ebbf0fc642908e26b58fd17f379920dbb1b387.zip |
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.
-rw-r--r-- | src/server.cpp | 27 |
1 files changed, 17 insertions, 10 deletions
diff --git a/src/server.cpp b/src/server.cpp index 83022e95b..f8e6846c3 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -327,17 +327,14 @@ Server::Server( Server::~Server() { - infostream<<"Server destructing"<<std::endl; + infostream << "Server destructing" << std::endl; // Send shutdown message SendChatMessage(PEER_ID_INEXISTENT, L"*** Server shutting down"); { MutexAutoLock envlock(m_env_mutex); - - // Execute script shutdown hooks - m_script->on_shutdown(); - + infostream << "Server: Saving players" << std::endl; m_env->saveLoadedPlayers(); @@ -353,6 +350,20 @@ Server::~Server() } m_env->kickAllPlayers(SERVER_ACCESSDENIED_SHUTDOWN, 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; m_env->saveMeta(); @@ -362,10 +373,6 @@ Server::~Server() stop(); 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 m_emerge; delete m_env; @@ -377,7 +384,7 @@ Server::~Server() delete m_craftdef; // Deinitialize scripting - infostream<<"Server: Deinitializing scripting"<<std::endl; + infostream << "Server: Deinitializing scripting" << std::endl; delete m_script; // Delete detached inventories |