mirror of
https://github.com/glest/glest-source.git
synced 2025-08-13 03:44:00 +02:00
- merged in willvarfar's particle patch
This commit is contained in:
@@ -38,13 +38,22 @@ static const char *getFolderTreeContentsCheckSumListRecursivelyCacheLookupKey1;
|
||||
static const char *getFolderTreeContentsCheckSumListRecursivelyCacheLookupKey2;
|
||||
|
||||
protected:
|
||||
static Mutex mutexCache;
|
||||
|
||||
typedef enum {
|
||||
cacheItemGet,
|
||||
cacheItemSet
|
||||
} CacheAccessorType;
|
||||
|
||||
template <typename T>
|
||||
static Mutex & manageCachedItemMutex(string cacheKey) {
|
||||
// Here is the actual type-safe instantiation
|
||||
static std::map<string, Mutex> itemCacheMutexList;
|
||||
if(itemCacheMutexList.find(cacheKey) == itemCacheMutexList.end()) {
|
||||
itemCacheMutexList[cacheKey] = Mutex();
|
||||
}
|
||||
Mutex &mutex = itemCacheMutexList[cacheKey];
|
||||
return mutex;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
static T & manageCachedItem(string cacheKey, T *value,CacheAccessorType accessor) {
|
||||
// Here is the actual type-safe instantiation
|
||||
@@ -52,6 +61,7 @@ protected:
|
||||
if(accessor == cacheItemSet) {
|
||||
if(value == NULL) {
|
||||
try {
|
||||
Mutex &mutexCache = manageCachedItemMutex<T>(cacheKey);
|
||||
MutexSafeWrapper safeMutex(&mutexCache);
|
||||
if(itemCache.find(cacheKey) != itemCache.end()) {
|
||||
itemCache.erase(cacheKey);
|
||||
@@ -64,6 +74,7 @@ protected:
|
||||
|
||||
}
|
||||
try {
|
||||
Mutex &mutexCache = manageCachedItemMutex<T>(cacheKey);
|
||||
MutexSafeWrapper safeMutex(&mutexCache);
|
||||
itemCache[cacheKey] = *value;
|
||||
safeMutex.ReleaseLock();
|
||||
@@ -94,6 +105,10 @@ public:
|
||||
return manageCachedItem<T>(cacheKey,NULL,cacheItemSet);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
static Mutex & getMutexForItem(string cacheKey) {
|
||||
return manageCachedItemMutex<T>(cacheKey);
|
||||
}
|
||||
};
|
||||
|
||||
}}//end namespace
|
||||
|
Reference in New Issue
Block a user