From 7b14d860c9380b7b329211d3ddbb33a48d86adca Mon Sep 17 00:00:00 2001 From: Mark Vejvoda Date: Sun, 3 Apr 2011 06:09:43 +0000 Subject: [PATCH] - attempt to log more info related to CRC processing - better thread mutex tracking --- source/glest_game/main/main.cpp | 7 +++++ .../sources/platform/common/base_thread.cpp | 9 ++++++ .../platform/common/platform_common.cpp | 28 +++++++++++++++++-- .../platform/common/simple_threads.cpp | 7 +++++ 4 files changed, 49 insertions(+), 2 deletions(-) diff --git a/source/glest_game/main/main.cpp b/source/glest_game/main/main.cpp index cb8fdacd..15c5670e 100644 --- a/source/glest_game/main/main.cpp +++ b/source/glest_game/main/main.cpp @@ -2019,6 +2019,13 @@ int glestMain(int argc, char** argv) { SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + //vector techPaths; + //vector techDataPaths = config.getPathListForType(ptTechs); + //findDirs(techDataPaths, techPaths); + + //int32 techCRC = getFolderTreeContentsCheckSumRecursively(techDataPaths, string("/") + "megapack" + string("/*"), ".xml", NULL, true); + //return -1; + // //removeFolder("/home/softcoder/Code/megaglest/trunk/mk/linux/mydata/tilesets/mother_board"); //return -1; diff --git a/source/shared_lib/sources/platform/common/base_thread.cpp b/source/shared_lib/sources/platform/common/base_thread.cpp index 63e7421d..8134c3e1 100644 --- a/source/shared_lib/sources/platform/common/base_thread.cpp +++ b/source/shared_lib/sources/platform/common/base_thread.cpp @@ -51,6 +51,7 @@ Mutex * BaseThread::getMutexThreadOwnerValid() { void BaseThread::setThreadOwnerValid(bool value) { static string mutexOwnerId = string(__FILE__) + string("_") + intToStr(__LINE__); MutexSafeWrapper safeMutex(&mutexThreadOwnerValid,mutexOwnerId); + mutexThreadOwnerValid.setOwnerId(mutexOwnerId); threadOwnerValid = value; safeMutex.ReleaseLock(); } @@ -59,6 +60,7 @@ bool BaseThread::getThreadOwnerValid() { bool ret = false; static string mutexOwnerId = string(__FILE__) + string("_") + intToStr(__LINE__); MutexSafeWrapper safeMutex(&mutexThreadOwnerValid,mutexOwnerId); + //mutexThreadOwnerValid.setOwnerId(mutexOwnerId); ret = threadOwnerValid; safeMutex.ReleaseLock(); @@ -74,6 +76,7 @@ void BaseThread::setQuitStatus(bool value) { static string mutexOwnerId = string(__FILE__) + string("_") + intToStr(__LINE__); MutexSafeWrapper safeMutex(&mutexQuit,mutexOwnerId); + mutexQuit.setOwnerId(mutexOwnerId); quit = value; safeMutex.ReleaseLock(); @@ -84,6 +87,7 @@ bool BaseThread::getQuitStatus() { bool retval = false; static string mutexOwnerId = string(__FILE__) + string("_") + intToStr(__LINE__); MutexSafeWrapper safeMutex(&mutexQuit,mutexOwnerId); + //mutexQuit.setOwnerId(mutexOwnerId); retval = quit; safeMutex.ReleaseLock(); @@ -94,6 +98,7 @@ bool BaseThread::getHasBeginExecution() { bool retval = false; static string mutexOwnerId = string(__FILE__) + string("_") + intToStr(__LINE__); MutexSafeWrapper safeMutex(&mutexBeginExecution,mutexOwnerId); + //mutexBeginExecution.setOwnerId(mutexOwnerId); retval = hasBeginExecution; safeMutex.ReleaseLock(); @@ -105,6 +110,7 @@ void BaseThread::setHasBeginExecution(bool value) { static string mutexOwnerId = string(__FILE__) + string("_") + intToStr(__LINE__); MutexSafeWrapper safeMutex(&mutexBeginExecution,mutexOwnerId); + mutexBeginExecution.setOwnerId(mutexOwnerId); hasBeginExecution = value; safeMutex.ReleaseLock(); @@ -129,6 +135,7 @@ bool BaseThread::getRunningStatus() { void BaseThread::setRunningStatus(bool value) { static string mutexOwnerId = string(__FILE__) + string("_") + intToStr(__LINE__); MutexSafeWrapper safeMutex(&mutexRunning,mutexOwnerId); + mutexRunning.setOwnerId(mutexOwnerId); running = value; if(value == true) { setHasBeginExecution(true); @@ -139,6 +146,7 @@ void BaseThread::setRunningStatus(bool value) { void BaseThread::setExecutingTask(bool value) { static string mutexOwnerId = string(__FILE__) + string("_") + intToStr(__LINE__); MutexSafeWrapper safeMutex(&mutexExecutingTask,mutexOwnerId); + mutexExecutingTask.setOwnerId(mutexOwnerId); executingTask = value; safeMutex.ReleaseLock(); } @@ -166,6 +174,7 @@ bool BaseThread::getDeleteSelfOnExecutionDone() { void BaseThread::setDeleteSelfOnExecutionDone(bool value) { static string mutexOwnerId = string(__FILE__) + string("_") + intToStr(__LINE__); MutexSafeWrapper safeMutex(&mutexDeleteSelfOnExecutionDone,mutexOwnerId); + mutexDeleteSelfOnExecutionDone.setOwnerId(mutexOwnerId); deleteSelfOnExecutionDone = value; } diff --git a/source/shared_lib/sources/platform/common/platform_common.cpp b/source/shared_lib/sources/platform/common/platform_common.cpp index 95604d85..95b2365d 100644 --- a/source/shared_lib/sources/platform/common/platform_common.cpp +++ b/source/shared_lib/sources/platform/common/platform_common.cpp @@ -617,12 +617,23 @@ int32 getFolderTreeContentsCheckSumRecursively(vector paths, string path string crcCacheFile = getFormattedCRCCacheFileName(cacheKeys); //if(SystemFlags::VERBOSE_MODE_ENABLED) printf("Looking for CRC Cache file [%s]\n",crcCacheFile.c_str()); + + if(recursiveChecksum == NULL) { + if(SystemFlags::VERBOSE_MODE_ENABLED) printf("\n-------------- In [%s::%s Line: %d] looking for cached CRC file [%s] for [%s] forceNoCache = %d -----------\n",__FILE__,__FUNCTION__,__LINE__,crcCacheFile.c_str(),pathSearchString.c_str(),forceNoCache); + } + int32 crcValue = 0; if(forceNoCache == false && hasCachedFileCRCValue(crcCacheFile, crcValue)) { crcTreeCache[cacheKey] = crcValue; - if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] scanning folders found CACHED FILE checksum = %d for cacheKey [%s]\n",__FILE__,__FUNCTION__,crcTreeCache[cacheKey],cacheKey.c_str()); + if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] scanning folders found CACHED FILE checksum = %d for cacheKey [%s] forceNoCache = %d\n",__FILE__,__FUNCTION__,crcTreeCache[cacheKey],cacheKey.c_str(),forceNoCache); return crcTreeCache[cacheKey]; } + else { + if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] scanning folders DID NOT FIND CACHED FILE checksum for cacheKey [%s] forceNoCache = %d\n",__FILE__,__FUNCTION__,cacheKey.c_str(),forceNoCache); + if(recursiveChecksum == NULL) { + if(SystemFlags::VERBOSE_MODE_ENABLED) printf("\n-------------- In [%s::%s] scanning folders DID NOT FIND CACHED FILE checksum for cacheKey [%s] forceNoCache = %d\n",__FILE__,__FUNCTION__,cacheKey.c_str(),forceNoCache); + } + } Checksum checksum = (recursiveChecksum == NULL ? Checksum() : *recursiveChecksum); for(unsigned int idx = 0; idx < paths.size(); ++idx) { @@ -683,12 +694,23 @@ int32 getFolderTreeContentsCheckSumRecursively(const string &path, const string string crcCacheFile = getFormattedCRCCacheFileName(cacheKeys); //if(SystemFlags::VERBOSE_MODE_ENABLED) printf("Looking for CRC Cache file [%s]\n",crcCacheFile.c_str()); + + if(recursiveChecksum == NULL) { + if(SystemFlags::VERBOSE_MODE_ENABLED) printf("\n-------------- In [%s::%s Line: %d] looking for cached CRC file [%s] for [%s] forceNoCache = %d -----------\n",__FILE__,__FUNCTION__,__LINE__,crcCacheFile.c_str(),path.c_str(),forceNoCache); + } + int32 crcValue = 0; if(forceNoCache == false && hasCachedFileCRCValue(crcCacheFile, crcValue)) { crcTreeCache[cacheKey] = crcValue; - if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] scanning folders found CACHED FILE checksum = %d for cacheKey [%s]\n",__FILE__,__FUNCTION__,crcTreeCache[cacheKey],cacheKey.c_str()); + if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] scanning folders found CACHED FILE checksum = %d for cacheKey [%s] forceNoCache = %d\n",__FILE__,__FUNCTION__,crcTreeCache[cacheKey],cacheKey.c_str(),forceNoCache); return crcTreeCache[cacheKey]; } + else { + if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] scanning folders DID NOT FIND CACHED FILE checksum for cacheKey [%s] forceNoCache = %d\n",__FILE__,__FUNCTION__,cacheKey.c_str(),forceNoCache); + if(recursiveChecksum == NULL) { + if(SystemFlags::VERBOSE_MODE_ENABLED) printf("\n-------------- In [%s::%s] scanning folders DID NOT FIND CACHED FILE checksum for cacheKey [%s] forceNoCache = %d\n",__FILE__,__FUNCTION__,cacheKey.c_str(),forceNoCache); + } + } bool topLevelCaller = (recursiveChecksum == NULL); Checksum checksum = (recursiveChecksum == NULL ? Checksum() : *recursiveChecksum); @@ -717,6 +739,7 @@ int32 getFolderTreeContentsCheckSumRecursively(const string &path, const string int fileMatchCount = 0; for(int i = 0; i < globbuf.gl_pathc; ++i) { const char* p = globbuf.gl_pathv[i]; + //printf("Line: %d p [%s]\n",__LINE__,p); if(isdir(p) == false) { bool addFile = true; @@ -761,6 +784,7 @@ int32 getFolderTreeContentsCheckSumRecursively(const string &path, const string continue; #endif const char *p = globbuf.gl_pathv[i]; + //printf("Line: %d p [%s]\n",__LINE__,p); string currentPath = p; endPathWithSlash(currentPath); diff --git a/source/shared_lib/sources/platform/common/simple_threads.cpp b/source/shared_lib/sources/platform/common/simple_threads.cpp index 24ddec8d..bd295d4b 100644 --- a/source/shared_lib/sources/platform/common/simple_threads.cpp +++ b/source/shared_lib/sources/platform/common/simple_threads.cpp @@ -234,6 +234,7 @@ void FileCRCPreCacheThread::addPendingTexture(Texture2D *texture) { } static string mutexOwnerId = string(__FILE__) + string("_") + intToStr(__LINE__); MutexSafeWrapper safeMutex(&mutexPendingTextureList,mutexOwnerId); + mutexPendingTextureList.setOwnerId(mutexOwnerId); pendingTextureList.push_back(texture); safeMutex.ReleaseLock(); } @@ -242,6 +243,7 @@ vector FileCRCPreCacheThread::getPendingTextureList(int maxTextures vector result; static string mutexOwnerId = string(__FILE__) + string("_") + intToStr(__LINE__); MutexSafeWrapper safeMutex(&mutexPendingTextureList,mutexOwnerId); + mutexPendingTextureList.setOwnerId(mutexOwnerId); unsigned int listCount = pendingTextureList.size(); if(listCount > 0) { if(maxTexturesToGet >= 0) { @@ -269,6 +271,7 @@ SimpleTaskThread::SimpleTaskThread( SimpleTaskCallbackInterface *simpleTaskInter static string mutexOwnerId = string(__FILE__) + string("_") + intToStr(__LINE__); MutexSafeWrapper safeMutex(&mutexLastExecuteTimestamp,mutexOwnerId); + mutexLastExecuteTimestamp.setOwnerId(mutexOwnerId); lastExecuteTimestamp = time(NULL); } @@ -276,6 +279,7 @@ bool SimpleTaskThread::isThreadExecutionLagging() { bool result = false; static string mutexOwnerId = string(__FILE__) + string("_") + intToStr(__LINE__); MutexSafeWrapper safeMutex(&mutexLastExecuteTimestamp,mutexOwnerId); + mutexLastExecuteTimestamp.setOwnerId(mutexOwnerId); result = (difftime(time(NULL),lastExecuteTimestamp) >= 5.0); safeMutex.ReleaseLock(); @@ -325,6 +329,7 @@ void SimpleTaskThread::execute() { static string mutexOwnerId = string(__FILE__) + string("_") + intToStr(__LINE__); MutexSafeWrapper safeMutex(&mutexLastExecuteTimestamp,mutexOwnerId); + mutexLastExecuteTimestamp.setOwnerId(mutexOwnerId); lastExecuteTimestamp = time(NULL); safeMutex.ReleaseLock(); } @@ -365,6 +370,7 @@ void SimpleTaskThread::execute() { void SimpleTaskThread::setTaskSignalled(bool value) { static string mutexOwnerId = string(__FILE__) + string("_") + intToStr(__LINE__); MutexSafeWrapper safeMutex(&mutexTaskSignaller,mutexOwnerId); + mutexTaskSignaller.setOwnerId(mutexOwnerId); taskSignalled = value; safeMutex.ReleaseLock(); } @@ -373,6 +379,7 @@ bool SimpleTaskThread::getTaskSignalled() { bool retval = false; static string mutexOwnerId = string(__FILE__) + string("_") + intToStr(__LINE__); MutexSafeWrapper safeMutex(&mutexTaskSignaller,mutexOwnerId); + mutexTaskSignaller.setOwnerId(mutexOwnerId); retval = taskSignalled; safeMutex.ReleaseLock();