summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--core/qthelper.cpp12
1 files changed, 8 insertions, 4 deletions
diff --git a/core/qthelper.cpp b/core/qthelper.cpp
index 325c1bcd6..058c2f253 100644
--- a/core/qthelper.cpp
+++ b/core/qthelper.cpp
@@ -1698,14 +1698,17 @@ char *intdup(int index)
QHash<int, double> factor_cache;
-QMutex factorCacheLock;
+QReadWriteLock factorCacheLock;
extern "C" double cache_value(int tissue, int timestep, enum inertgas inertgas)
{
+ double value;
int key = (timestep << 5) + (tissue << 1);
if (inertgas == HE)
++key;
- QMutexLocker locker(&factorCacheLock);
- return factor_cache.value(key);
+ factorCacheLock.lockForRead();
+ value = factor_cache.value(key);
+ factorCacheLock.unlock();
+ return value;
}
extern "C" void cache_insert(int tissue, int timestep, enum inertgas inertgas, double value)
@@ -1713,8 +1716,9 @@ extern "C" void cache_insert(int tissue, int timestep, enum inertgas inertgas, d
int key = (timestep << 5) + (tissue << 1);
if (inertgas == HE)
++key;
- QMutexLocker locker(&factorCacheLock);
+ factorCacheLock.lockForWrite();
factor_cache.insert(key, value);
+ factorCacheLock.unlock();
}
extern "C" void print_qt_versions()