From d32de80491f97df520e23a29167067a9dc81b7df Mon Sep 17 00:00:00 2001 From: Mark Vejvoda Date: Sun, 10 Nov 2013 21:55:22 +0000 Subject: [PATCH] bugfix for precache crc thread unpause on game end --- source/glest_game/main/main.cpp | 1 + .../include/platform/common/simple_threads.h | 5 +++++ .../sources/platform/common/simple_threads.cpp | 10 ++++++++++ 3 files changed, 16 insertions(+) diff --git a/source/glest_game/main/main.cpp b/source/glest_game/main/main.cpp index e18c1a27..1f8e7a36 100644 --- a/source/glest_game/main/main.cpp +++ b/source/glest_game/main/main.cpp @@ -5292,6 +5292,7 @@ int glestMain(int argc, char** argv) { static string mutexOwnerId = string(extractFileFromDirectoryPath(__FILE__).c_str()) + string("_") + intToStr(__LINE__); vector techDataPaths = config.getPathListForType(ptTechs); + FileCRCPreCacheThread::setPreCacheThreadCacheLookupKey(GameConstants::preCacheThreadCacheLookupKey); FileCRCPreCacheThread * &preCacheCRCThreadPtr = CacheManager::getCachedItem< FileCRCPreCacheThread * >(GameConstants::preCacheThreadCacheLookupKey); if(preCacheCRCThreadPtr == NULL) { preCacheCRCThreadPtr = new FileCRCPreCacheThread(); diff --git a/source/shared_lib/include/platform/common/simple_threads.h b/source/shared_lib/include/platform/common/simple_threads.h index 9f6b6761..9e183d09 100644 --- a/source/shared_lib/include/platform/common/simple_threads.h +++ b/source/shared_lib/include/platform/common/simple_threads.h @@ -47,6 +47,7 @@ protected: Mutex mutexPendingTextureList; vector pendingTextureList; + static string preCacheThreadCacheLookupKey; Mutex mutexPauseForGame; bool pauseForGame; std::vector preCacheWorkerThreadList; @@ -57,6 +58,10 @@ protected: public: FileCRCPreCacheThread(); FileCRCPreCacheThread(vector techDataPaths,vector workerThreadTechPaths,FileCRCPreCacheThreadCallbackInterface *processTechCB); + virtual ~FileCRCPreCacheThread(); + + static void setPreCacheThreadCacheLookupKey(string value) { preCacheThreadCacheLookupKey = value; } + virtual void execute(); void setTechDataPaths(vector value) { this->techDataPaths = value; } void setWorkerThreadTechPaths(vector value) { this->workerThreadTechPaths = value; } diff --git a/source/shared_lib/sources/platform/common/simple_threads.cpp b/source/shared_lib/sources/platform/common/simple_threads.cpp index 22aa490a..bfcdd359 100644 --- a/source/shared_lib/sources/platform/common/simple_threads.cpp +++ b/source/shared_lib/sources/platform/common/simple_threads.cpp @@ -16,6 +16,7 @@ #include #include "conversion.h" #include "platform_util.h" +#include "cache_manager.h" #include "leak_dumper.h" using namespace std; @@ -26,6 +27,7 @@ namespace Shared { namespace PlatformCommon { const static int MAX_FileCRCPreCacheThread_WORKER_THREADS = 3; const static double PAUSE_SECONDS_BETWEEN_WORKERS = 15; +string FileCRCPreCacheThread::preCacheThreadCacheLookupKey = ""; FileCRCPreCacheThread::FileCRCPreCacheThread() : BaseThread() { techDataPaths.clear(); @@ -45,6 +47,14 @@ FileCRCPreCacheThread::FileCRCPreCacheThread(vector techDataPaths, uniqueID = "FileCRCPreCacheThread"; } +FileCRCPreCacheThread::~FileCRCPreCacheThread() { + bool threadControllerMode = (workerThreadTechPaths.size() == 0); + FileCRCPreCacheThread * &preCacheCRCThreadPtr = CacheManager::getCachedItem< FileCRCPreCacheThread * >(preCacheThreadCacheLookupKey); + if(preCacheCRCThreadPtr != NULL && threadControllerMode == true) { + preCacheCRCThreadPtr = NULL; + } +} + void FileCRCPreCacheThread::setPauseForGame(bool pauseForGame) { static string mutexOwnerId = CODE_AT_LINE; MutexSafeWrapper safeMutex(&mutexPauseForGame,mutexOwnerId);