Fix Settings locking

This commit is contained in:
ShadowNinja 2014-09-11 14:23:04 -04:00
parent cd64a92a8c
commit 2ae5d3f3ab

@ -741,9 +741,7 @@ public:
void clear() void clear()
{ {
JMutexAutoLock lock(m_mutex); JMutexAutoLock lock(m_mutex);
clearNoLock();
m_settings.clear();
m_defaults.clear();
} }
void updateValue(const Settings &other, const std::string &name) void updateValue(const Settings &other, const std::string &name)
@ -758,8 +756,6 @@ public:
m_settings[name] = val; m_settings[name] = val;
} catch (SettingNotFoundException &e) { } catch (SettingNotFoundException &e) {
} }
return;
} }
void update(const Settings &other) void update(const Settings &other)
@ -770,17 +766,14 @@ public:
JMutexAutoLock lock(m_mutex); JMutexAutoLock lock(m_mutex);
JMutexAutoLock lock2(other.m_mutex); JMutexAutoLock lock2(other.m_mutex);
m_settings.insert(other.m_settings.begin(), other.m_settings.end()); updateNoLock(other);
m_defaults.insert(other.m_defaults.begin(), other.m_defaults.end());
return;
} }
Settings & operator+=(const Settings &other) Settings & operator+=(const Settings &other)
{ {
update(other); update(other);
return *this;
return *this;
} }
Settings & operator=(const Settings &other) Settings & operator=(const Settings &other)
@ -791,14 +784,27 @@ public:
JMutexAutoLock lock(m_mutex); JMutexAutoLock lock(m_mutex);
JMutexAutoLock lock2(other.m_mutex); JMutexAutoLock lock2(other.m_mutex);
clearNoLock();
clear(); updateNoLock(other);
update(other);
return *this; return *this;
} }
private: private:
void updateNoLock(const Settings &other)
{
m_settings.insert(other.m_settings.begin(), other.m_settings.end());
m_defaults.insert(other.m_defaults.begin(), other.m_defaults.end());
}
void clearNoLock()
{
m_settings.clear();
m_defaults.clear();
}
std::map<std::string, std::string> m_settings; std::map<std::string, std::string> m_settings;
std::map<std::string, std::string> m_defaults; std::map<std::string, std::string> m_defaults;
// All methods that access m_settings/m_defaults directly should lock this. // All methods that access m_settings/m_defaults directly should lock this.