fixed concurrentmap
This commit is contained in:
+5
-5
@@ -32,21 +32,21 @@ public:
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
TValue
|
||||||
getOrAdd(const TKey &name, TValue &value, std::function<TValue()> addLambda)
|
getOrAdd(const TKey &name, std::function<TValue()> addLambda)
|
||||||
{
|
{
|
||||||
this->mutex->lock();
|
this->mutex->lock();
|
||||||
auto a = map.find(name);
|
auto a = map.find(name);
|
||||||
|
|
||||||
if (a == map.end()) {
|
if (a == map.end()) {
|
||||||
value = addLambda();
|
TValue value = addLambda();
|
||||||
map.insert(name, value);
|
map.insert(name, value);
|
||||||
this->mutex->unlock();
|
this->mutex->unlock();
|
||||||
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
value = a.value();
|
|
||||||
|
|
||||||
this->mutex->unlock();
|
this->mutex->unlock();
|
||||||
|
return a.value();
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|||||||
Reference in New Issue
Block a user