From 2c490d42292fe2214aca27109740409eb02e1d39 Mon Sep 17 00:00:00 2001 From: "madmaxoft@gmail.com" Date: Sun, 15 Jul 2012 20:07:38 +0000 Subject: [PATCH] World threads are stopped before the plugin mgr for clean exit (FS #228) git-svn-id: http://mc-server.googlecode.com/svn/trunk@669 0a769ca7-a7f5-676a-18bf-c427514a06d6 --- source/cRoot.cpp | 14 ++++++++++++++ source/cRoot.h | 4 ++++ source/cWorld.cpp | 13 ++++++++++--- source/cWorld.h | 5 ++++- 4 files changed, 32 insertions(+), 4 deletions(-) diff --git a/source/cRoot.cpp b/source/cRoot.cpp index 9ab923d50..ef234044f 100644 --- a/source/cRoot.cpp +++ b/source/cRoot.cpp @@ -162,6 +162,8 @@ void cRoot::Start() // Deallocate stuffs LOG("Shutting down server..."); m_Server->Shutdown(); // This waits for threads to stop and d/c clients + LOG("Stopping world threads..."); + StopWorlds(); LOG("Stopping authenticator..."); m_Authenticator.Stop(); LOG("Stopping plugin manager..."); @@ -253,6 +255,18 @@ void cRoot::StartWorlds(void) +void cRoot::StopWorlds(void) +{ + for( WorldMap::iterator itr = m_pState->WorldsByName.begin(); itr != m_pState->WorldsByName.end(); ++itr ) + { + itr->second->StopThreads(); + } +} + + + + + void cRoot::UnloadWorlds(void) { for( WorldMap::iterator itr = m_pState->WorldsByName.begin(); itr != m_pState->WorldsByName.end(); ++itr ) diff --git a/source/cRoot.h b/source/cRoot.h index 21bd39f7d..fc12d876c 100644 --- a/source/cRoot.h +++ b/source/cRoot.h @@ -78,6 +78,10 @@ private: /// Starts each world's life void StartWorlds(void); + /// Stops each world's threads, so that it's safe to unload them + void StopWorlds(void); + + /// Unloads all worlds from memory void UnloadWorlds(void); cServer * m_Server; diff --git a/source/cWorld.cpp b/source/cWorld.cpp index 187642242..980d09cdb 100644 --- a/source/cWorld.cpp +++ b/source/cWorld.cpp @@ -208,9 +208,6 @@ cWorld::~cWorld() delete m_FireSimulator; delete m_RedstoneSimulator; - m_Generator.Stop(); - m_ChunkSender.Stop(); - UnloadUnusedChunks(); m_Storage.WaitForFinish(); @@ -510,6 +507,16 @@ void cWorld::InitializeSpawn(void) +void cWorld::StopThreads(void) +{ + m_Generator.Stop(); + m_ChunkSender.Stop(); +} + + + + + void cWorld::Tick(float a_Dt) { m_Time += a_Dt / 1000.f; diff --git a/source/cWorld.h b/source/cWorld.h index fd594f22b..0a4d0280e 100644 --- a/source/cWorld.h +++ b/source/cWorld.h @@ -326,7 +326,10 @@ public: void Tick(float a_Dt); - void InitializeSpawn(); + void InitializeSpawn(void); + + /// Stops threads that belong to this world (part of deinit) + void StopThreads(void); void CastThunderbolt (int a_X, int a_Y, int a_Z); //tolua_export void SetWeather ( eWeather a_Weather ); //tolua_export