mirror of
https://github.com/glest/glest-source.git
synced 2025-08-19 06:31:19 +02:00
- threadsafe cache manager and recursive checking in xml loader (possible fix for issue experienced by james in windows build)
This commit is contained in:
@@ -38,6 +38,8 @@ static const char *getFolderTreeContentsCheckSumListRecursivelyCacheLookupKey1;
|
|||||||
static const char *getFolderTreeContentsCheckSumListRecursivelyCacheLookupKey2;
|
static const char *getFolderTreeContentsCheckSumListRecursivelyCacheLookupKey2;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
static std::map<string, Mutex *> itemCacheMutexList;
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
cacheItemGet,
|
cacheItemGet,
|
||||||
cacheItemSet
|
cacheItemSet
|
||||||
@@ -45,13 +47,11 @@ protected:
|
|||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
static Mutex & manageCachedItemMutex(string cacheKey) {
|
static Mutex & manageCachedItemMutex(string cacheKey) {
|
||||||
// Here is the actual type-safe instantiation
|
|
||||||
static std::map<string, Mutex> itemCacheMutexList;
|
|
||||||
if(itemCacheMutexList.find(cacheKey) == itemCacheMutexList.end()) {
|
if(itemCacheMutexList.find(cacheKey) == itemCacheMutexList.end()) {
|
||||||
itemCacheMutexList[cacheKey] = Mutex();
|
itemCacheMutexList[cacheKey] = new Mutex();
|
||||||
}
|
}
|
||||||
Mutex &mutex = itemCacheMutexList[cacheKey];
|
Mutex *mutex = itemCacheMutexList[cacheKey];
|
||||||
return mutex;
|
return *mutex;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
@@ -84,13 +84,22 @@ protected:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// If this is the first access we return a default object of the type
|
// If this is the first access we return a default object of the type
|
||||||
|
Mutex &mutexCache = manageCachedItemMutex<T>(cacheKey);
|
||||||
|
MutexSafeWrapper safeMutex(&mutexCache);
|
||||||
|
|
||||||
return itemCache[cacheKey];
|
return itemCache[cacheKey];
|
||||||
}
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
CacheManager() { }
|
CacheManager() { }
|
||||||
~CacheManager() { }
|
~CacheManager() {
|
||||||
|
for(std::map<string, Mutex *>::iterator iterMap = itemCacheMutexList.begin();
|
||||||
|
iterMap != itemCacheMutexList.end(); iterMap++) {
|
||||||
|
delete iterMap->second;
|
||||||
|
iterMap->second = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
static void setCachedItem(string cacheKey, const T value) {
|
static void setCachedItem(string cacheKey, const T value) {
|
||||||
|
@@ -14,6 +14,7 @@
|
|||||||
namespace Shared { namespace PlatformCommon {
|
namespace Shared { namespace PlatformCommon {
|
||||||
|
|
||||||
//Mutex CacheManager::mutexCache;
|
//Mutex CacheManager::mutexCache;
|
||||||
|
std::map<string, Mutex *> CacheManager::itemCacheMutexList;
|
||||||
const char *CacheManager::getFolderTreeContentsCheckSumRecursivelyCacheLookupKey1 = "CRC_Cache_FileTree1";
|
const char *CacheManager::getFolderTreeContentsCheckSumRecursivelyCacheLookupKey1 = "CRC_Cache_FileTree1";
|
||||||
const char *CacheManager::getFolderTreeContentsCheckSumRecursivelyCacheLookupKey2 = "CRC_Cache_FileTree2";
|
const char *CacheManager::getFolderTreeContentsCheckSumRecursivelyCacheLookupKey2 = "CRC_Cache_FileTree2";
|
||||||
const char *CacheManager::getFolderTreeContentsCheckSumListRecursivelyCacheLookupKey1 = "CRC_Cache_FileTreeList1";
|
const char *CacheManager::getFolderTreeContentsCheckSumListRecursivelyCacheLookupKey1 = "CRC_Cache_FileTreeList1";
|
||||||
|
@@ -176,16 +176,16 @@ void XmlTree::init(const string &name){
|
|||||||
}
|
}
|
||||||
|
|
||||||
typedef std::vector<XmlTree*> LoadStack;
|
typedef std::vector<XmlTree*> LoadStack;
|
||||||
static LoadStack loadStack;
|
//static LoadStack loadStack;
|
||||||
//static string loadStackCacheName = string(__FILE__) + string("_loadStackCacheName");
|
static string loadStackCacheName = string(__FILE__) + string("_loadStackCacheName");
|
||||||
|
|
||||||
void XmlTree::load(const string &path, std::map<string,string> mapTagReplacementValues) {
|
void XmlTree::load(const string &path, std::map<string,string> mapTagReplacementValues) {
|
||||||
//printf("XmlTree::load p [%p]\n",this);
|
//printf("XmlTree::load p [%p]\n",this);
|
||||||
assert(!loadPath.size());
|
assert(!loadPath.size());
|
||||||
|
|
||||||
//LoadStack &loadStack = CacheManager::getCachedItem<LoadStack>(loadStackCacheName);
|
LoadStack &loadStack = CacheManager::getCachedItem<LoadStack>(loadStackCacheName);
|
||||||
//Mutex &mutex = CacheManager::getMutexForItem<LoadStack>(loadStackCacheName);
|
Mutex &mutex = CacheManager::getMutexForItem<LoadStack>(loadStackCacheName);
|
||||||
//MutexSafeWrapper safeMutex(&mutex);
|
MutexSafeWrapper safeMutex(&mutex);
|
||||||
|
|
||||||
for(LoadStack::iterator it= loadStack.begin(); it!= loadStack.end(); it++){
|
for(LoadStack::iterator it= loadStack.begin(); it!= loadStack.end(); it++){
|
||||||
if((*it)->loadPath == path){
|
if((*it)->loadPath == path){
|
||||||
@@ -193,6 +193,7 @@ void XmlTree::load(const string &path, std::map<string,string> mapTagReplacement
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
loadStack.push_back(this);
|
loadStack.push_back(this);
|
||||||
|
safeMutex.ReleaseLock();
|
||||||
|
|
||||||
loadPath = path;
|
loadPath = path;
|
||||||
this->rootNode= XmlIo::getInstance().load(path, mapTagReplacementValues);
|
this->rootNode= XmlIo::getInstance().load(path, mapTagReplacementValues);
|
||||||
@@ -205,14 +206,16 @@ void XmlTree::save(const string &path){
|
|||||||
XmlTree::~XmlTree() {
|
XmlTree::~XmlTree() {
|
||||||
//printf("XmlTree::~XmlTree p [%p]\n",this);
|
//printf("XmlTree::~XmlTree p [%p]\n",this);
|
||||||
|
|
||||||
//LoadStack &loadStack = CacheManager::getCachedItem<LoadStack>(loadStackCacheName);
|
LoadStack &loadStack = CacheManager::getCachedItem<LoadStack>(loadStackCacheName);
|
||||||
//Mutex &mutex = CacheManager::getMutexForItem<LoadStack>(loadStackCacheName);
|
Mutex &mutex = CacheManager::getMutexForItem<LoadStack>(loadStackCacheName);
|
||||||
//MutexSafeWrapper safeMutex(&mutex);
|
MutexSafeWrapper safeMutex(&mutex);
|
||||||
|
|
||||||
LoadStack::iterator it= find(loadStack.begin(),loadStack.end(),this);
|
LoadStack::iterator it= find(loadStack.begin(),loadStack.end(),this);
|
||||||
if(it != loadStack.end()) {
|
if(it != loadStack.end()) {
|
||||||
loadStack.erase(it);
|
loadStack.erase(it);
|
||||||
}
|
}
|
||||||
|
safeMutex.ReleaseLock();
|
||||||
|
|
||||||
delete rootNode;
|
delete rootNode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user