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>
This commit is contained in:
Robert C. Helling 2017-12-18 16:24:34 +01:00 committed by Dirk Hohndel
parent 9d844801b9
commit 3985a8aa8f

View file

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