- merged in willvarfar's particle patch

This commit is contained in:
Mark Vejvoda
2011-07-06 22:23:51 +00:00
parent 9ef8c82441
commit 1b2d4fddea
19 changed files with 624 additions and 218 deletions

View File

@@ -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