From 884b46da6016b938f4d8627156bd484032783a69 Mon Sep 17 00:00:00 2001 From: Mark Vejvoda Date: Fri, 25 Mar 2011 22:50:30 +0000 Subject: [PATCH] - more thread cleanup --- source/glest_game/main/main.cpp | 5 ++-- source/glest_game/menu/menu_state_mods.cpp | 25 +++++++++++++++++-- .../platform/common/simple_threads.cpp | 2 +- 3 files changed, 27 insertions(+), 5 deletions(-) diff --git a/source/glest_game/main/main.cpp b/source/glest_game/main/main.cpp index f43c82ed..96fd6e2f 100644 --- a/source/glest_game/main/main.cpp +++ b/source/glest_game/main/main.cpp @@ -2119,8 +2119,9 @@ int glestMain(int argc, char** argv) { if(preCacheThread.get() != NULL) { time_t elapsed = time(NULL); - for(;preCacheThread->shutdownAndWait() == false && - difftime(time(NULL),elapsed) <= 5;) { + preCacheThread->signalQuit(); + for(;preCacheThread->canShutdown(false) == false && + difftime(time(NULL),elapsed) <= 15;) { sleep(50); } } diff --git a/source/glest_game/menu/menu_state_mods.cpp b/source/glest_game/menu/menu_state_mods.cpp index a23ec7fd..90306920 100644 --- a/source/glest_game/menu/menu_state_mods.cpp +++ b/source/glest_game/menu/menu_state_mods.cpp @@ -368,6 +368,12 @@ MenuStateMods::MenuStateMods(Program *program, MainMenu *mainMenu) : } void MenuStateMods::simpleTask(BaseThread *callingThread) { + + MutexSafeWrapper safeMutexThreadOwner(callingThread->getMutexThreadOwnerValid(),string(__FILE__) + "_" + intToStr(__LINE__)); + if(callingThread->getQuitStatus() == true || safeMutexThreadOwner.isValidMutex() == false) { + return; + } + std::string techsMetaData = ""; std::string tilesetsMetaData = ""; std::string mapsMetaData = ""; @@ -386,6 +392,10 @@ void MenuStateMods::simpleTask(BaseThread *callingThread) { SystemFlags::cleanupHTTP(&handle); } + if(callingThread->getQuitStatus() == true || safeMutexThreadOwner.isValidMutex() == false) { + return; + } + tilesetListRemote.clear(); Tokenize(tilesetsMetaData,tilesetListRemote,"\n"); @@ -429,6 +439,10 @@ void MenuStateMods::simpleTask(BaseThread *callingThread) { } } + if(callingThread->getQuitStatus() == true || safeMutexThreadOwner.isValidMutex() == false) { + return; + } + techListRemote.clear(); Tokenize(techsMetaData,techListRemote,"\n"); @@ -489,6 +503,10 @@ void MenuStateMods::simpleTask(BaseThread *callingThread) { } } + if(callingThread->getQuitStatus() == true || safeMutexThreadOwner.isValidMutex() == false) { + return; + } + mapListRemote.clear(); Tokenize(mapsMetaData,mapListRemote,"\n"); @@ -546,6 +564,10 @@ void MenuStateMods::simpleTask(BaseThread *callingThread) { } } + if(callingThread->getQuitStatus() == true || safeMutexThreadOwner.isValidMutex() == false) { + return; + } + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); int listBoxLength = 400; @@ -741,8 +763,7 @@ MenuStateMods::~MenuStateMods() { modHttpServerThread->setThreadOwnerValid(false); SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__); - if( modHttpServerThread->canShutdown(true) == true && - modHttpServerThread->shutdownAndWait() == true) { + if( modHttpServerThread->shutdownAndWait() == true) { delete modHttpServerThread; } modHttpServerThread = NULL; diff --git a/source/shared_lib/sources/platform/common/simple_threads.cpp b/source/shared_lib/sources/platform/common/simple_threads.cpp index 3eaf6ad6..11e4f4ac 100644 --- a/source/shared_lib/sources/platform/common/simple_threads.cpp +++ b/source/shared_lib/sources/platform/common/simple_threads.cpp @@ -137,7 +137,7 @@ void FileCRCPreCacheThread::execute() { if( getQuitStatus() == false && hasRunningWorkerThread == true) { - sleep(20); + sleep(10); } } if(SystemFlags::VERBOSE_MODE_ENABLED) printf("********************** CRC Controller thread took %.2f seconds END **********************\n",difftime(time(NULL),elapsedTime));