From 3985a8aa8f07370049589f9326c19b6a4330426d Mon Sep 17 00:00:00 2001 From: "Robert C. Helling" Date: Mon, 18 Dec 2017 16:24:34 +0100 Subject: 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 --- core/qthelper.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'core/qthelper.cpp') 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 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() -- cgit v1.2.3-70-g09d2