From 2ee657fb0cabeda1eb282ef82f30d7f6e5a191ff Mon Sep 17 00:00:00 2001 From: Gunnar Beutner Date: Wed, 11 Sep 2013 10:28:47 +0200 Subject: [PATCH] ido: Fix initialization order bug. --- lib/ido/dbtype.cpp | 14 +++++++++----- lib/ido/dbtype.h | 2 +- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/lib/ido/dbtype.cpp b/lib/ido/dbtype.cpp index 3fec66868..d283b8aba 100644 --- a/lib/ido/dbtype.cpp +++ b/lib/ido/dbtype.cpp @@ -27,8 +27,6 @@ using namespace icinga; -boost::mutex DbType::m_StaticMutex; - DbType::DbType(const String& name, const String& table, long tid, const String& idcolumn, const DbType::ObjectFactory& factory) : m_Name(name), m_Table(table), m_TypeID(tid), m_IDColumn(idcolumn), m_ObjectFactory(factory) { } @@ -55,13 +53,13 @@ String DbType::GetIDColumn(void) const void DbType::RegisterType(const DbType::Ptr& type) { - boost::mutex::scoped_lock lock(m_StaticMutex); + boost::mutex::scoped_lock lock(GetStaticMutex()); GetTypes()[type->GetName()] = type; } DbType::Ptr DbType::GetByName(const String& name) { - boost::mutex::scoped_lock lock(m_StaticMutex); + boost::mutex::scoped_lock lock(GetStaticMutex()); DbType::TypeMap::const_iterator it = GetTypes().find(name); if (it == GetTypes().end()) @@ -99,8 +97,14 @@ DbObject::Ptr DbType::GetOrCreateObjectByName(const String& name1, const String& return dbobj; } +boost::mutex& DbType::GetStaticMutex(void) +{ + static boost::mutex mutex; + return mutex; +} + /** - * Caller must hold m_StaticMutex. + * Caller must hold static mutex. */ DbType::TypeMap& DbType::GetTypes(void) { diff --git a/lib/ido/dbtype.h b/lib/ido/dbtype.h index 43212deb6..ed0e00cc7 100644 --- a/lib/ido/dbtype.h +++ b/lib/ido/dbtype.h @@ -64,7 +64,7 @@ private: String m_IDColumn; ObjectFactory m_ObjectFactory; - static boost::mutex m_StaticMutex; + static boost::mutex& GetStaticMutex(void); static TypeMap& GetTypes(void); ObjectMap& GetObjects(void); -- 2.50.1