From 8534fa59a93011be7586f52c3ac7bbd56e07a128 Mon Sep 17 00:00:00 2001 From: Mark Vejvoda Date: Wed, 22 Dec 2010 00:15:32 +0000 Subject: [PATCH] - added more stable way of setting thread run state --- source/glest_game/network/connection_slot.cpp | 8 ++++---- .../sources/platform/common/simple_threads.cpp | 17 +++-------------- 2 files changed, 7 insertions(+), 18 deletions(-) diff --git a/source/glest_game/network/connection_slot.cpp b/source/glest_game/network/connection_slot.cpp index 79132f46..bb907343 100644 --- a/source/glest_game/network/connection_slot.cpp +++ b/source/glest_game/network/connection_slot.cpp @@ -92,9 +92,9 @@ bool ConnectionSlotThread::isSignalCompleted() { } void ConnectionSlotThread::execute() { + RunningStatusSafeWrapper runningStatus(this); try { - setRunningStatus(true); - + //setRunningStatus(true); SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); unsigned int idx = 0; @@ -132,7 +132,7 @@ void ConnectionSlotThread::execute() { SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); } catch(const exception &ex) { - setRunningStatus(false); + //setRunningStatus(false); SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] Error [%s]\n",__FILE__,__FUNCTION__,__LINE__,ex.what()); SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); @@ -140,7 +140,7 @@ void ConnectionSlotThread::execute() { throw runtime_error(ex.what()); } SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__); - setRunningStatus(false); + //setRunningStatus(false); } // ===================================================== diff --git a/source/shared_lib/sources/platform/common/simple_threads.cpp b/source/shared_lib/sources/platform/common/simple_threads.cpp index 076fe2de..52cc0f6e 100644 --- a/source/shared_lib/sources/platform/common/simple_threads.cpp +++ b/source/shared_lib/sources/platform/common/simple_threads.cpp @@ -23,14 +23,13 @@ FileCRCPreCacheThread::FileCRCPreCacheThread() : BaseThread() { } void FileCRCPreCacheThread::execute() { + RunningStatusSafeWrapper runningStatus(this); SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); if(getQuitStatus() == true) { - setRunningStatus(false); return; } - setRunningStatus(true); SystemFlags::OutputDebug(SystemFlags::debugNetwork,"FILE CRC PreCache thread is running\n"); try { @@ -61,20 +60,16 @@ void FileCRCPreCacheThread::execute() { catch(const exception &ex) { SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] Error [%s]\n",__FILE__,__FUNCTION__,__LINE__,ex.what()); SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] error [%s]\n",__FILE__,__FUNCTION__,__LINE__,ex.what()); - setRunningStatus(false); } catch(...) { SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] UNKNOWN Error\n",__FILE__,__FUNCTION__,__LINE__); SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] unknown error\n",__FILE__,__FUNCTION__,__LINE__); - setRunningStatus(false); } SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] FILE CRC PreCache thread is exiting\n",__FILE__,__FUNCTION__,__LINE__); - setRunningStatus(false); } - -SimpleTaskThread::SimpleTaskThread( SimpleTaskCallbackInterface *simpleTaskInterface, +SimpleTaskThread::SimpleTaskThread( SimpleTaskCallbackInterface *simpleTaskInterface, unsigned int executionCount, unsigned int millisecsBetweenExecutions, bool needTaskSignal) : BaseThread() { @@ -91,12 +86,11 @@ bool SimpleTaskThread::canShutdown() { } void SimpleTaskThread::execute() { + RunningStatusSafeWrapper runningStatus(this); try { if(getQuitStatus() == true) { - setRunningStatus(false); return; } - setRunningStatus(true); SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] uniqueID [%s]\n",__FILE__,__FUNCTION__,__LINE__,this->getUniqueID().c_str()); @@ -150,15 +144,10 @@ void SimpleTaskThread::execute() { } catch(const exception &ex) { SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] Error [%s]\n",__FILE__,__FUNCTION__,__LINE__,ex.what()); - - setRunningStatus(false); - SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] uniqueID [%s]\n",__FILE__,__FUNCTION__,__LINE__,this->getUniqueID().c_str()); throw runtime_error(ex.what()); } - SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] uniqueID [%s]\n",__FILE__,__FUNCTION__,__LINE__,this->getUniqueID().c_str()); - setRunningStatus(false); SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] uniqueID [%s] END\n",__FILE__,__FUNCTION__,__LINE__,this->getUniqueID().c_str()); }