diff --git a/source/glest_game/menu/menu_state_connected_game.cpp b/source/glest_game/menu/menu_state_connected_game.cpp index db4f13cda..d91f9f7bf 100644 --- a/source/glest_game/menu/menu_state_connected_game.cpp +++ b/source/glest_game/menu/menu_state_connected_game.cpp @@ -55,8 +55,8 @@ struct FormatString { // class MenuStateConnectedGame // ===================================================== -MenuStateConnectedGame::MenuStateConnectedGame(Program *program, MainMenu *mainMenu,JoinMenu joinMenuInfo, bool openNetworkSlots): - MenuState(program, mainMenu, "connected-game") +MenuStateConnectedGame::MenuStateConnectedGame(Program *program, MainMenu *mainMenu,JoinMenu joinMenuInfo, bool openNetworkSlots) : + MenuState(program, mainMenu, "connected-game"), modHttpServerThread(NULL) { //printf("In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); @@ -779,9 +779,9 @@ MenuStateConnectedGame::~MenuStateConnectedGame() { if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__); if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__); - modHttpServerThread->setThreadOwnerValid(false); + modHttpServerThread->setSimpleTaskInterfaceValid(false); modHttpServerThread->signalQuit(); - //modHttpServerThread->setThreadOwnerValid(false); + modHttpServerThread->setThreadOwnerValid(false); if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__); if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__); diff --git a/source/shared_lib/include/platform/common/simple_threads.h b/source/shared_lib/include/platform/common/simple_threads.h index 3853b3a6a..66f434d72 100644 --- a/source/shared_lib/include/platform/common/simple_threads.h +++ b/source/shared_lib/include/platform/common/simple_threads.h @@ -83,6 +83,8 @@ class SimpleTaskThread : public BaseThread { protected: + Mutex mutexSimpleTaskInterfaceValid; + bool simpleTaskInterfaceValid; SimpleTaskCallbackInterface *simpleTaskInterface; unsigned int executionCount; unsigned int millisecsBetweenExecutions; @@ -114,6 +116,9 @@ public: void cleanup(); void setOverrideShutdownTask(taskFunctionCallback *ptr); + + bool getSimpleTaskInterfaceValid() const { return this->simpleTaskInterfaceValid; } + void setSimpleTaskInterfaceValid(bool value) { this->simpleTaskInterfaceValid = value; } }; // ===================================================== diff --git a/source/shared_lib/sources/platform/common/simple_threads.cpp b/source/shared_lib/sources/platform/common/simple_threads.cpp index 005d06de3..699c70100 100644 --- a/source/shared_lib/sources/platform/common/simple_threads.cpp +++ b/source/shared_lib/sources/platform/common/simple_threads.cpp @@ -350,6 +350,7 @@ SimpleTaskThread::SimpleTaskThread( SimpleTaskCallbackInterface *simpleTaskInter overrideShutdownTask(NULL) { uniqueID = "SimpleTaskThread"; this->simpleTaskInterface = simpleTaskInterface; + this->simpleTaskInterfaceValid = (this->simpleTaskInterface != NULL); this->executionCount = executionCount; this->millisecsBetweenExecutions = millisecsBetweenExecutions; this->needTaskSignal = needTaskSignal; @@ -363,7 +364,12 @@ SimpleTaskThread::SimpleTaskThread( SimpleTaskCallbackInterface *simpleTaskInter mutexLastExecuteTimestamp.setOwnerId(mutexOwnerId); lastExecuteTimestamp = time(NULL); - this->simpleTaskInterface->setupTask(this); + string mutexOwnerId1 = string(__FILE__) + string("_") + intToStr(__LINE__); + MutexSafeWrapper safeMutex1(&mutexSimpleTaskInterfaceValid,mutexOwnerId1); + if(this->simpleTaskInterfaceValid == true) { + safeMutex1.ReleaseLock(); + this->simpleTaskInterface->setupTask(this); + } } SimpleTaskThread::~SimpleTaskThread() { @@ -385,8 +391,13 @@ void SimpleTaskThread::cleanup() { this->overrideShutdownTask = NULL; } else if(this->simpleTaskInterface != NULL) { - this->simpleTaskInterface->shutdownTask(this); - this->simpleTaskInterface = NULL; + string mutexOwnerId1 = string(__FILE__) + string("_") + intToStr(__LINE__); + MutexSafeWrapper safeMutex1(&mutexSimpleTaskInterfaceValid,mutexOwnerId1); + if(this->simpleTaskInterfaceValid == true) { + safeMutex1.ReleaseLock(); + this->simpleTaskInterface->shutdownTask(this); + this->simpleTaskInterface = NULL; + } } } @@ -434,6 +445,13 @@ void SimpleTaskThread::execute() { unsigned int idx = 0; for(;this->simpleTaskInterface != NULL;) { + string mutexOwnerId1 = string(__FILE__) + string("_") + intToStr(__LINE__); + MutexSafeWrapper safeMutex1(&mutexSimpleTaskInterfaceValid,mutexOwnerId1); + if(this->simpleTaskInterfaceValid == false) { + break; + } + safeMutex1.ReleaseLock(); + bool runTask = true; if(needTaskSignal == true) { runTask = getTaskSignalled();