- better stability of menu navigation and threads

This commit is contained in:
Mark Vejvoda
2010-12-07 06:12:51 +00:00
parent 8c115809ce
commit 1e0a5dc304
2 changed files with 77 additions and 52 deletions

View File

@@ -520,24 +520,31 @@ MenuStateCustomGame::~MenuStateCustomGame() {
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__); SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
if(publishToMasterserverThreadInDeletion == false) { if(publishToMasterserverThreadInDeletion == false) {
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
MutexSafeWrapper safeMutexPtr(&publishToMasterserverThreadPtrChangeAccessor); MutexSafeWrapper safeMutexPtr(&publishToMasterserverThreadPtrChangeAccessor);
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
if(publishToMasterserverThread != NULL) { if(publishToMasterserverThread != NULL) {
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
needToBroadcastServerSettings = false; needToBroadcastServerSettings = false;
needToRepublishToMasterserver = false; needToRepublishToMasterserver = false;
//BaseThread::shutdownAndWait(publishToMasterserverThread); //BaseThread::shutdownAndWait(publishToMasterserverThread);
if(publishToMasterserverThread != NULL && if(publishToMasterserverThread != NULL &&
publishToMasterserverThread->shutdownAndWait() == true) { publishToMasterserverThread->shutdownAndWait() == true) {
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
delete publishToMasterserverThread; delete publishToMasterserverThread;
publishToMasterserverThread = NULL;
} }
publishToMasterserverThread = NULL;
publishToMasterserverThreadInDeletion = false; publishToMasterserverThreadInDeletion = false;
safeMutexPtr.ReleaseLock(); safeMutexPtr.ReleaseLock();
} }
else { else {
safeMutexPtr.ReleaseLock(); safeMutexPtr.ReleaseLock();
} }
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
} }
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__); SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
@@ -562,8 +569,9 @@ void MenuStateCustomGame::returnToParentMenu(){
if(publishToMasterserverThread != NULL && if(publishToMasterserverThread != NULL &&
publishToMasterserverThread->shutdownAndWait() == true) { publishToMasterserverThread->shutdownAndWait() == true) {
delete publishToMasterserverThread; delete publishToMasterserverThread;
publishToMasterserverThread = NULL;
} }
publishToMasterserverThread = NULL;
publishToMasterserverThreadInDeletion = false; publishToMasterserverThreadInDeletion = false;
safeMutexPtr.ReleaseLock(); safeMutexPtr.ReleaseLock();
@@ -614,8 +622,9 @@ void MenuStateCustomGame::mouseClick(int x, int y, MouseButton mouseButton){
if(publishToMasterserverThread != NULL && if(publishToMasterserverThread != NULL &&
publishToMasterserverThread->shutdownAndWait() == true) { publishToMasterserverThread->shutdownAndWait() == true) {
delete publishToMasterserverThread; delete publishToMasterserverThread;
publishToMasterserverThread = NULL;
} }
publishToMasterserverThread = NULL;
publishToMasterserverThreadInDeletion = false; publishToMasterserverThreadInDeletion = false;
safeMutexPtr.ReleaseLock(); safeMutexPtr.ReleaseLock();
@@ -1127,8 +1136,9 @@ void MenuStateCustomGame::PlayNow() {
if(publishToMasterserverThread != NULL && if(publishToMasterserverThread != NULL &&
publishToMasterserverThread->shutdownAndWait() == true) { publishToMasterserverThread->shutdownAndWait() == true) {
delete publishToMasterserverThread; delete publishToMasterserverThread;
publishToMasterserverThread = NULL;
} }
publishToMasterserverThread = NULL;
publishToMasterserverThreadInDeletion = false; publishToMasterserverThreadInDeletion = false;
safeMutexPtr.ReleaseLock(); safeMutexPtr.ReleaseLock();
@@ -1877,6 +1887,11 @@ void MenuStateCustomGame::simpleTask() {
bool needPing = (difftime(time(NULL),lastNetworkPing) >= GameConstants::networkPingInterval); bool needPing = (difftime(time(NULL),lastNetworkPing) >= GameConstants::networkPingInterval);
safeMutex.ReleaseLock(); safeMutex.ReleaseLock();
if( publishToMasterserverThread == NULL ||
publishToMasterserverThread->getQuitStatus() == true) {
return;
}
if(republish == true) { if(republish == true) {
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__); SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
@@ -1911,6 +1926,11 @@ void MenuStateCustomGame::simpleTask() {
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__); SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
if( publishToMasterserverThread == NULL ||
publishToMasterserverThread->getQuitStatus() == true) {
return;
}
if(broadCastSettings) { if(broadCastSettings) {
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__); SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
@@ -1938,6 +1958,11 @@ void MenuStateCustomGame::simpleTask() {
} }
} }
if( publishToMasterserverThread == NULL ||
publishToMasterserverThread->getQuitStatus() == true) {
return;
}
if(needPing == true) { if(needPing == true) {
lastNetworkPing = time(NULL); lastNetworkPing = time(NULL);

View File

@@ -142,7 +142,7 @@ bool BaseThread::shutdownAndWait() {
int maxWaitSeconds = 7; int maxWaitSeconds = 7;
if(pThread->canShutdown() == false) { if(pThread->canShutdown() == false) {
maxWaitSeconds = 3; maxWaitSeconds = 2;
} }
for( time_t elapsed = time(NULL); difftime(time(NULL),elapsed) <= maxWaitSeconds; ) { for( time_t elapsed = time(NULL); difftime(time(NULL),elapsed) <= maxWaitSeconds; ) {