mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-21 22:24:07 +01:00
improved concurrency of concurrentmap
This commit is contained in:
parent
04e1ce4ba5
commit
a29f76dce2
1 changed files with 6 additions and 6 deletions
|
@ -27,26 +27,26 @@ public:
|
||||||
this->mutex->unlock();
|
this->mutex->unlock();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
this->mutex->unlock();
|
|
||||||
value = a.value();
|
value = a.value();
|
||||||
|
this->mutex->unlock();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
TValue
|
void
|
||||||
getOrAdd(const TKey &name, std::function<TValue()> addLambda)
|
getOrAdd(const TKey &name, TValue &value, 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()) {
|
||||||
TValue value = addLambda();
|
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
|
||||||
|
|
Loading…
Reference in a new issue