From 8845c3803898d4e674fd49c3c7997bbc4759da7f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20=C3=96nnerby?= Date: Mon, 11 Aug 2008 10:04:08 +0000 Subject: [PATCH] Added a second mutex in the Preferences::IO class. --- src/core/Preferences.cpp | 6 ++++++ src/core/Preferences.h | 4 ++++ 2 files changed, 10 insertions(+) diff --git a/src/core/Preferences.cpp b/src/core/Preferences.cpp index 455617b6a..06bb8b667 100644 --- a/src/core/Preferences.cpp +++ b/src/core/Preferences.cpp @@ -61,6 +61,8 @@ Preferences::~Preferences(void){ bool Preferences::GetBool(const char* key,bool defaultValue){ + boost::mutex::scoped_lock lock(IO::Instance()->mutex); + IO::SettingMap::iterator setting = this->settings->find(key); if(setting!=this->settings->end()){ return setting->second.Value(defaultValue); @@ -70,6 +72,7 @@ bool Preferences::GetBool(const char* key,bool defaultValue){ } int Preferences::GetInt(const char* key,int defaultValue){ + boost::mutex::scoped_lock lock(IO::Instance()->mutex); IO::SettingMap::iterator setting = this->settings->find(key); if(setting!=this->settings->end()){ return setting->second.Value(defaultValue); @@ -79,6 +82,7 @@ int Preferences::GetInt(const char* key,int defaultValue){ } utfstring Preferences::GetString(const char* key,const utfchar* defaultValue){ + boost::mutex::scoped_lock lock(IO::Instance()->mutex); IO::SettingMap::iterator setting = this->settings->find(key); if(setting!=this->settings->end()){ return setting->second.Value(utfstring(defaultValue)); @@ -98,6 +102,7 @@ Preferences::IO::Ptr Preferences::IO::Instance(){ } Preferences::IO::IO(void){ + boost::mutex::scoped_lock lock(this->mutex); utfstring dataDir = GetDataDirectory(); utfstring dbFile = GetDataDirectory() + UTF("settings.db"); this->db.Open(dbFile.c_str(),0,128); @@ -234,6 +239,7 @@ utfstring Preferences::Setting::Value(utfstring defaultValue){ Preferences::IO::SettingMapPtr Preferences::IO::GetNamespace(const char* nameSpace){ + boost::mutex::scoped_lock lock(this->mutex); // First check if it's in the NamespaceMap NamespaceMap::iterator ns = this->namespaces.find(nameSpace); if(ns!=this->namespaces.end()){ diff --git a/src/core/Preferences.h b/src/core/Preferences.h index 12ef13c09..8e3ff2c03 100644 --- a/src/core/Preferences.h +++ b/src/core/Preferences.h @@ -41,6 +41,7 @@ #include #include +#include ////////////////////////////////////////////////////////////////////////////// @@ -101,6 +102,9 @@ class Preferences{ void SaveSetting(const char* nameSpace,const char *key,Setting &setting); static IO::Ptr Instance(); + + boost::mutex mutex; + private: db::Connection db; NamespaceMap namespaces;