From a29f76dce2e8b5717054186c662d6fdb25f8638d Mon Sep 17 00:00:00 2001 From: fourtf Date: Sun, 29 Jan 2017 13:40:04 +0100 Subject: [PATCH] improved concurrency of concurrentmap --- concurrentmap.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/concurrentmap.h b/concurrentmap.h index 45cf3b626..e4068f925 100644 --- a/concurrentmap.h +++ b/concurrentmap.h @@ -27,26 +27,26 @@ public: this->mutex->unlock(); return false; } - this->mutex->unlock(); value = a.value(); + this->mutex->unlock(); return true; } - TValue - getOrAdd(const TKey &name, std::function addLambda) + void + getOrAdd(const TKey &name, TValue &value, std::function addLambda) { this->mutex->lock(); auto a = map.find(name); if (a == map.end()) { - TValue value = addLambda(); + value = addLambda(); map.insert(name, value); this->mutex->unlock(); - return value; } + value = a.value(); + this->mutex->unlock(); - return a.value(); } void