From 22eb5cc4d446bb60c6417a4fb1212795e8676771 Mon Sep 17 00:00:00 2001 From: Mark Vejvoda Date: Sat, 1 Jun 2013 06:28:03 +0000 Subject: [PATCH] attempt to fix a thread bug when starting a game --- .../menu/menu_state_connected_game.cpp | 16 ++++------------ .../include/platform/common/simple_threads.h | 4 ++-- .../sources/platform/common/simple_threads.cpp | 13 +++++++++++++ 3 files changed, 19 insertions(+), 14 deletions(-) diff --git a/source/glest_game/menu/menu_state_connected_game.cpp b/source/glest_game/menu/menu_state_connected_game.cpp index d91f9f7bf..02cb390ae 100644 --- a/source/glest_game/menu/menu_state_connected_game.cpp +++ b/source/glest_game/menu/menu_state_connected_game.cpp @@ -976,22 +976,12 @@ void MenuStateConnectedGame::simpleTask(BaseThread *callingThread) { Lang &lang= Lang::getInstance(); Config &config = Config::getInstance(); -// string fileArchiveExtractCommand = config.getString("FileArchiveExtractCommand",""); -// int expectedResult = config.getInt("FileArchiveExtractCommandSuccessResult","0"); -// bool findArchive = executeShellCommand(fileArchiveExtractCommand,expectedResult); -// if(findArchive == false) { -// mainMessageBoxState = ftpmsg_None; -// mainMessageBox.init(lang.get("Ok"),450); -// showMessageBox(lang.get("ModRequires7z"), lang.get("Notice"), true); -// } std::string techsMetaData = ""; std::string tilesetsMetaData = ""; std::string mapsMetaData = ""; std::string scenariosMetaData = ""; - //modMenuState=mmst_Loading; - if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__); if(config.getString("Masterserver","") != "") { @@ -1005,6 +995,7 @@ void MenuStateConnectedGame::simpleTask(BaseThread *callingThread) { CURL *handle = SystemFlags::initHTTP(); CURLcode curlResult = CURLE_OK; techsMetaData = SystemFlags::getHTTP(baseURL + "showTechsForGlest.php"+phpVersionParam+gameVersion+playerUUID,handle,-1,&curlResult); + if(SystemFlags::VERBOSE_MODE_ENABLED) printf("techsMetaData [%s] curlResult = %d\n",techsMetaData.c_str(),curlResult); if(callingThread->getQuitStatus() == true || safeMutexThreadOwner.isValidMutex() == false) { @@ -1167,8 +1158,6 @@ void MenuStateConnectedGame::simpleTask(BaseThread *callingThread) { 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__); - //modMenuState=mmst_None; - if(modHttpServerThread != NULL) { modHttpServerThread->signalQuit(); } @@ -2304,6 +2293,8 @@ void MenuStateConnectedGame::returnToJoinMenu() { if(modHttpServerThread != NULL) { 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->setSimpleTaskInterfaceValid(false); modHttpServerThread->signalQuit(); //modHttpServerThread->setThreadOwnerValid(false); @@ -3369,6 +3360,7 @@ void MenuStateConnectedGame::update() { if(modHttpServerThread != NULL) { 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->setSimpleTaskInterfaceValid(false); modHttpServerThread->signalQuit(); //modHttpServerThread->setThreadOwnerValid(false); diff --git a/source/shared_lib/include/platform/common/simple_threads.h b/source/shared_lib/include/platform/common/simple_threads.h index 66f434d72..308ea27d3 100644 --- a/source/shared_lib/include/platform/common/simple_threads.h +++ b/source/shared_lib/include/platform/common/simple_threads.h @@ -117,8 +117,8 @@ public: void setOverrideShutdownTask(taskFunctionCallback *ptr); - bool getSimpleTaskInterfaceValid() const { return this->simpleTaskInterfaceValid; } - void setSimpleTaskInterfaceValid(bool value) { this->simpleTaskInterfaceValid = value; } + bool getSimpleTaskInterfaceValid(); + void setSimpleTaskInterfaceValid(bool value); }; // ===================================================== diff --git a/source/shared_lib/sources/platform/common/simple_threads.cpp b/source/shared_lib/sources/platform/common/simple_threads.cpp index 699c70100..a64b5af1f 100644 --- a/source/shared_lib/sources/platform/common/simple_threads.cpp +++ b/source/shared_lib/sources/platform/common/simple_threads.cpp @@ -427,6 +427,19 @@ bool SimpleTaskThread::canShutdown(bool deleteSelfIfShutdownDelayed) { return ret; } +bool SimpleTaskThread::getSimpleTaskInterfaceValid() { + string mutexOwnerId1 = string(__FILE__) + string("_") + intToStr(__LINE__); + MutexSafeWrapper safeMutex1(&mutexSimpleTaskInterfaceValid,mutexOwnerId1); + + return this->simpleTaskInterfaceValid; +} +void SimpleTaskThread::setSimpleTaskInterfaceValid(bool value) { + string mutexOwnerId1 = string(__FILE__) + string("_") + intToStr(__LINE__); + MutexSafeWrapper safeMutex1(&mutexSimpleTaskInterfaceValid,mutexOwnerId1); + + this->simpleTaskInterfaceValid = value; +} + void SimpleTaskThread::execute() { if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); void *ptr_cpy = this->ptr;