refactoring

This commit is contained in:
fourtf
2017-04-12 17:46:44 +02:00
parent 8ef492d7ae
commit 96db82e867
114 changed files with 5554 additions and 3703 deletions
+18 -22
View File
@@ -14,17 +14,16 @@ class ConcurrentMap
{
public:
ConcurrentMap()
: map()
: _map()
{
}
bool
tryGet(const TKey &name, TValue &value) const
bool tryGet(const TKey &name, TValue &value) const
{
QMutexLocker lock(&this->mutex);
QMutexLocker lock(&_mutex);
auto a = map.find(name);
if (a == map.end()) {
auto a = _map.find(name);
if (a == _map.end()) {
return false;
}
@@ -33,40 +32,37 @@ public:
return true;
}
TValue
getOrAdd(const TKey &name, std::function<TValue()> addLambda)
TValue getOrAdd(const TKey &name, std::function<TValue()> addLambda)
{
QMutexLocker lock(&this->mutex);
QMutexLocker lock(&_mutex);
auto a = map.find(name);
if (a == map.end()) {
auto a = _map.find(name);
if (a == _map.end()) {
TValue value = addLambda();
map.insert(name, value);
_map.insert(name, value);
return value;
}
return a.value();
}
void
clear()
void clear()
{
QMutexLocker lock(&this->mutex);
QMutexLocker lock(&_mutex);
map.clear();
_map.clear();
}
void
insert(const TKey &name, const TValue &value)
void insert(const TKey &name, const TValue &value)
{
QMutexLocker lock(&this->mutex);
QMutexLocker lock(&_mutex);
map.insert(name, value);
_map.insert(name, value);
}
private:
mutable QMutex mutex;
QMap<TKey, TValue> map;
mutable QMutex _mutex;
QMap<TKey, TValue> _map;
};
} // namespace chatterino