summaryrefslogtreecommitdiff
path: root/src/settings.h
diff options
context:
space:
mode:
authorShadowNinja <shadowninja@minetest.net>2014-09-11 14:23:04 -0400
committerShadowNinja <shadowninja@minetest.net>2014-09-21 14:39:35 -0400
commit2ae5d3f3abc7ac5ee96c4dfc7eeead045fdc775e (patch)
treed743b3292a0849e155b10707b0996a347acc3a13 /src/settings.h
parentcd64a92a8cde573404e8af9e220d4e1c6ce6453e (diff)
downloadminetest-2ae5d3f3abc7ac5ee96c4dfc7eeead045fdc775e.tar.gz
minetest-2ae5d3f3abc7ac5ee96c4dfc7eeead045fdc775e.tar.bz2
minetest-2ae5d3f3abc7ac5ee96c4dfc7eeead045fdc775e.zip
Fix Settings locking
Diffstat (limited to 'src/settings.h')
-rw-r--r--src/settings.h32
1 files changed, 19 insertions, 13 deletions
diff --git a/src/settings.h b/src/settings.h
index 6300ddd6f..bfe7dd5a4 100644
--- a/src/settings.h
+++ b/src/settings.h
@@ -741,9 +741,7 @@ public:
void clear()
{
JMutexAutoLock lock(m_mutex);
-
- m_settings.clear();
- m_defaults.clear();
+ clearNoLock();
}
void updateValue(const Settings &other, const std::string &name)
@@ -758,8 +756,6 @@ public:
m_settings[name] = val;
} catch (SettingNotFoundException &e) {
}
-
- return;
}
void update(const Settings &other)
@@ -770,17 +766,14 @@ public:
JMutexAutoLock lock(m_mutex);
JMutexAutoLock lock2(other.m_mutex);
- m_settings.insert(other.m_settings.begin(), other.m_settings.end());
- m_defaults.insert(other.m_defaults.begin(), other.m_defaults.end());
-
- return;
+ updateNoLock(other);
}
Settings & operator+=(const Settings &other)
{
update(other);
- return *this;
+ return *this;
}
Settings & operator=(const Settings &other)
@@ -791,14 +784,27 @@ public:
JMutexAutoLock lock(m_mutex);
JMutexAutoLock lock2(other.m_mutex);
-
- clear();
- update(other);
+ clearNoLock();
+ updateNoLock(other);
return *this;
}
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_defaults;
// All methods that access m_settings/m_defaults directly should lock this.