]> granicus.if.org Git - icinga2/commitdiff
ido: Fix initialization order bug.
authorGunnar Beutner <gunnar.beutner@netways.de>
Wed, 11 Sep 2013 08:28:47 +0000 (10:28 +0200)
committerGunnar Beutner <gunnar.beutner@netways.de>
Wed, 11 Sep 2013 08:28:47 +0000 (10:28 +0200)
lib/ido/dbtype.cpp
lib/ido/dbtype.h

index 3fec66868177836b01b4a8d332d3cda03b45b533..d283b8abafb9a910ceda44a386962ebeccec07bc 100644 (file)
@@ -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)
 {
index 43212deb69ccf495575a1b629b16891cccf96e43..ed0e00cc78bafea5c41c1986b368242c86383c1d 100644 (file)
@@ -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);