summaryrefslogtreecommitdiff
path: root/src/settings.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/settings.cpp')
-rw-r--r--src/settings.cpp50
1 files changed, 28 insertions, 22 deletions
diff --git a/src/settings.cpp b/src/settings.cpp
index e95bd436d..56afa6133 100644
--- a/src/settings.cpp
+++ b/src/settings.cpp
@@ -20,8 +20,8 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "settings.h"
#include "irrlichttypes_bloated.h"
#include "exceptions.h"
-#include "jthread/jmutexautolock.h"
-#include "strfnd.h"
+#include "threading/mutex_auto_lock.h"
+#include "util/strfnd.h"
#include <iostream>
#include <fstream>
#include <sstream>
@@ -56,8 +56,8 @@ Settings & Settings::operator = (const Settings &other)
if (&other == this)
return *this;
- JMutexAutoLock lock(m_mutex);
- JMutexAutoLock lock2(other.m_mutex);
+ MutexAutoLock lock(m_mutex);
+ MutexAutoLock lock2(other.m_mutex);
clearNoLock();
updateNoLock(other);
@@ -155,7 +155,7 @@ bool Settings::readConfigFile(const char *filename)
bool Settings::parseConfigLines(std::istream &is, const std::string &end)
{
- JMutexAutoLock lock(m_mutex);
+ MutexAutoLock lock(m_mutex);
std::string line, name, value;
@@ -194,7 +194,7 @@ bool Settings::parseConfigLines(std::istream &is, const std::string &end)
void Settings::writeLines(std::ostream &os, u32 tab_depth) const
{
- JMutexAutoLock lock(m_mutex);
+ MutexAutoLock lock(m_mutex);
for (std::map<std::string, SettingsEntry>::const_iterator
it = m_settings.begin();
@@ -298,7 +298,7 @@ bool Settings::updateConfigObject(std::istream &is, std::ostream &os,
bool Settings::updateConfigFile(const char *filename)
{
- JMutexAutoLock lock(m_mutex);
+ MutexAutoLock lock(m_mutex);
std::ifstream is(filename);
std::ostringstream os(std::ios_base::binary);
@@ -379,7 +379,7 @@ bool Settings::parseCommandLine(int argc, char *argv[],
const SettingsEntry &Settings::getEntry(const std::string &name) const
{
- JMutexAutoLock lock(m_mutex);
+ MutexAutoLock lock(m_mutex);
std::map<std::string, SettingsEntry>::const_iterator n;
if ((n = m_settings.find(name)) == m_settings.end()) {
@@ -562,7 +562,7 @@ bool Settings::getNoiseParamsFromGroup(const std::string &name,
bool Settings::exists(const std::string &name) const
{
- JMutexAutoLock lock(m_mutex);
+ MutexAutoLock lock(m_mutex);
return (m_settings.find(name) != m_settings.end() ||
m_defaults.find(name) != m_defaults.end());
@@ -742,7 +742,7 @@ bool Settings::setEntry(const std::string &name, const void *data,
return false;
{
- JMutexAutoLock lock(m_mutex);
+ MutexAutoLock lock(m_mutex);
SettingsEntry &entry = set_default ? m_defaults[name] : m_settings[name];
old_group = entry.group;
@@ -878,22 +878,28 @@ bool Settings::setNoiseParams(const std::string &name,
bool Settings::remove(const std::string &name)
{
- JMutexAutoLock lock(m_mutex);
+ MutexAutoLock lock(m_mutex);
- delete m_settings[name].group;
- return m_settings.erase(name);
+ std::map<std::string, SettingsEntry>::iterator it = m_settings.find(name);
+ if (it != m_settings.end()) {
+ delete it->second.group;
+ m_settings.erase(it);
+ return true;
+ } else {
+ return false;
+ }
}
void Settings::clear()
{
- JMutexAutoLock lock(m_mutex);
+ MutexAutoLock lock(m_mutex);
clearNoLock();
}
void Settings::clearDefaults()
{
- JMutexAutoLock lock(m_mutex);
+ MutexAutoLock lock(m_mutex);
clearDefaultsNoLock();
}
@@ -902,7 +908,7 @@ void Settings::updateValue(const Settings &other, const std::string &name)
if (&other == this)
return;
- JMutexAutoLock lock(m_mutex);
+ MutexAutoLock lock(m_mutex);
try {
std::string val = other.get(name);
@@ -918,8 +924,8 @@ void Settings::update(const Settings &other)
if (&other == this)
return;
- JMutexAutoLock lock(m_mutex);
- JMutexAutoLock lock2(other.m_mutex);
+ MutexAutoLock lock(m_mutex);
+ MutexAutoLock lock2(other.m_mutex);
updateNoLock(other);
}
@@ -982,13 +988,13 @@ void Settings::clearDefaultsNoLock()
void Settings::registerChangedCallback(std::string name,
setting_changed_callback cbf, void *userdata)
{
- JMutexAutoLock lock(m_callbackMutex);
+ MutexAutoLock lock(m_callbackMutex);
m_callbacks[name].push_back(std::make_pair(cbf, userdata));
}
void Settings::deregisterChangedCallback(std::string name, setting_changed_callback cbf, void *userdata)
{
- JMutexAutoLock lock(m_callbackMutex);
+ MutexAutoLock lock(m_callbackMutex);
std::map<std::string, std::vector<std::pair<setting_changed_callback, void*> > >::iterator iterToVector = m_callbacks.find(name);
if (iterToVector != m_callbacks.end())
{
@@ -1004,12 +1010,12 @@ void Settings::deregisterChangedCallback(std::string name, setting_changed_callb
void Settings::doCallbacks(const std::string name)
{
- JMutexAutoLock lock(m_callbackMutex);
+ MutexAutoLock lock(m_callbackMutex);
std::map<std::string, std::vector<std::pair<setting_changed_callback, void*> > >::iterator iterToVector = m_callbacks.find(name);
if (iterToVector != m_callbacks.end())
{
std::vector<std::pair<setting_changed_callback, void*> >::iterator iter;
- for (iter = iterToVector->second.begin(); iter != iterToVector->second.end(); iter++)
+ for (iter = iterToVector->second.begin(); iter != iterToVector->second.end(); ++iter)
{
(iter->first)(name, iter->second);
}