From 9be57384633dfb3d030715ebc9e8007c4ffe8a71 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20=C3=96nnerby?= Date: Mon, 11 Aug 2008 06:58:31 +0000 Subject: [PATCH] Made musik::core::Preferences threadsafe. --- src/core/Preferences.cpp | 10 +++++++--- src/core/Preferences.h | 1 + 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/core/Preferences.cpp b/src/core/Preferences.cpp index 5a002e6c7..455617b6a 100644 --- a/src/core/Preferences.cpp +++ b/src/core/Preferences.cpp @@ -41,6 +41,7 @@ #include #include +#include ////////////////////////////////////////////////////////////////////////////// @@ -48,10 +49,10 @@ using namespace musik::core; ////////////////////////////////////////////////////////////////////////////// -Preferences::Preferences(const char* nameSpace) : - nameSpace(nameSpace), - IOPtr(IO::Instance()) +Preferences::Preferences(const char* nameSpace) + :nameSpace(nameSpace) { + this->IOPtr = IO::Instance(); this->settings = this->IOPtr->GetNamespace(nameSpace); } @@ -89,6 +90,9 @@ utfstring Preferences::GetString(const char* key,const utfchar* defaultValue){ ////////////////////////////////////////////////////////////////////////////// Preferences::IO::Ptr Preferences::IO::Instance(){ + static boost::mutex instanceMutex; + boost::mutex::scoped_lock oLock(instanceMutex); + static IO::Ptr sInstance(new Preferences::IO()); return sInstance; } diff --git a/src/core/Preferences.h b/src/core/Preferences.h index 52be21547..12ef13c09 100644 --- a/src/core/Preferences.h +++ b/src/core/Preferences.h @@ -104,6 +104,7 @@ class Preferences{ private: db::Connection db; NamespaceMap namespaces; + };