ido: Fix initialization order bug.

This commit is contained in:
Gunnar Beutner 2013-09-11 10:28:47 +02:00
parent a9b7cfb777
commit 2ee657fb0c
2 changed files with 10 additions and 6 deletions

View File

@ -27,8 +27,6 @@
using namespace icinga; 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) 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) : 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) void DbType::RegisterType(const DbType::Ptr& type)
{ {
boost::mutex::scoped_lock lock(m_StaticMutex); boost::mutex::scoped_lock lock(GetStaticMutex());
GetTypes()[type->GetName()] = type; GetTypes()[type->GetName()] = type;
} }
DbType::Ptr DbType::GetByName(const String& name) 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); DbType::TypeMap::const_iterator it = GetTypes().find(name);
if (it == GetTypes().end()) if (it == GetTypes().end())
@ -99,8 +97,14 @@ DbObject::Ptr DbType::GetOrCreateObjectByName(const String& name1, const String&
return dbobj; 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) DbType::TypeMap& DbType::GetTypes(void)
{ {

View File

@ -64,7 +64,7 @@ private:
String m_IDColumn; String m_IDColumn;
ObjectFactory m_ObjectFactory; ObjectFactory m_ObjectFactory;
static boost::mutex m_StaticMutex; static boost::mutex& GetStaticMutex(void);
static TypeMap& GetTypes(void); static TypeMap& GetTypes(void);
ObjectMap& GetObjects(void); ObjectMap& GetObjects(void);