summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Robert C. Helling <helling@atdotde.de>2017-12-18 16:24:34 +0100
committerGravatar Dirk Hohndel <dirk@hohndel.org>2017-12-18 11:29:17 -0800
commit3985a8aa8f07370049589f9326c19b6a4330426d (patch)
tree05a26cf5bfcf65dfe33ea24e18f605839fab8098
parent9d844801b9da94bcec7653acd5b5de8167da4134 (diff)
downloadsubsurface-3985a8aa8f07370049589f9326c19b6a4330426d.tar.gz
Allow to read factor cache concurrently
In a session with the profile I saw that the planner spends a lot of time waiting to obtain the lock for the factor cache. Most of the time we are only reading that cache and that is save to do in parallel (according to the Qt IRC channel). So we can use a QReadWriteLock instead of a QMutex. This appears to be quite a performance boost, in particular for VPM-B Signed-off-by: Robert C. Helling <helling@atdotde.de>
-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()