diff --git a/lib/base/dynamictype.cpp b/lib/base/dynamictype.cpp index d20d83de6..9d7adabbe 100644 --- a/lib/base/dynamictype.cpp +++ b/lib/base/dynamictype.cpp @@ -28,7 +28,9 @@ using namespace icinga; DynamicType::DynamicType(const String& name) : m_Name(name) -{ } +{ + InflateMutex(); +} DynamicType::Ptr DynamicType::GetByName(const String& name) { diff --git a/lib/base/object.cpp b/lib/base/object.cpp index eba735b37..b36bd4a59 100644 --- a/lib/base/object.cpp +++ b/lib/base/object.cpp @@ -59,6 +59,11 @@ bool Object::OwnsLock(void) const } #endif /* _DEBUG */ +void Object::InflateMutex(void) +{ + m_Mutex.Inflate(); +} + void Object::SetField(int, const Value&) { BOOST_THROW_EXCEPTION(std::runtime_error("Invalid field ID.")); diff --git a/lib/base/object.hpp b/lib/base/object.hpp index bfb8fe5c4..2b6bb8c93 100644 --- a/lib/base/object.hpp +++ b/lib/base/object.hpp @@ -99,6 +99,8 @@ public: bool OwnsLock(void) const; #endif /* _DEBUG */ + void InflateMutex(void); + private: Object(const Object& other); Object& operator=(const Object& rhs); diff --git a/lib/base/thinmutex.hpp b/lib/base/thinmutex.hpp index ab85ef37f..b600293f7 100644 --- a/lib/base/thinmutex.hpp +++ b/lib/base/thinmutex.hpp @@ -67,26 +67,7 @@ public: #endif /* _DEBUG */ } - inline void Spin(unsigned int it) - { - if (it < 8) { - /* Do nothing. */ - } -#ifdef SPIN_PAUSE - else if (it < 16) { - SPIN_PAUSE(); - } -#endif /* SPIN_PAUSE */ - else { -#ifdef _WIN32 - Sleep(0); -#else /* _WIN32 */ - sched_yield(); -#endif /* _WIN32 */ - } - } - - inline void Lock(void) + inline void Lock(bool make_native = false) { bool contended = false; unsigned int it = 0; @@ -111,16 +92,10 @@ public: it++; } - if (contended) + if (contended || make_native) MakeNative(); } - void MakeNative(void); - void DestroyNative(void); - - void LockNative(void); - void UnlockNative(void); - inline void Unlock(void) { #ifdef _WIN32 @@ -135,10 +110,43 @@ public: UnlockNative(); } + inline void Inflate(void) + { + Lock(true); + Unlock(); + } + #ifdef _DEBUG static void DebugTimerHandler(void); #endif /* _DEBUG */ +private: + inline void Spin(unsigned int it) + { + if (it < 8) { + /* Do nothing. */ + } +#ifdef SPIN_PAUSE + else if (it < 16) { + SPIN_PAUSE(); + } +#endif /* SPIN_PAUSE */ + else { +#ifdef _WIN32 + DebugBreak(); + Sleep(0); +#else /* _WIN32 */ + sched_yield(); +#endif /* _WIN32 */ + } + } + + void MakeNative(void); + void DestroyNative(void); + + void LockNative(void); + void UnlockNative(void); + private: #ifdef _WIN32 # ifdef _WIN64 diff --git a/lib/config/configitem.cpp b/lib/config/configitem.cpp index 53ac6e317..26be1d8a3 100644 --- a/lib/config/configitem.cpp +++ b/lib/config/configitem.cpp @@ -137,9 +137,7 @@ DynamicObject::Ptr ConfigItem::Commit(bool discard) /* Make sure the type is valid. */ Type::Ptr type = Type::GetByName(GetType()); - - if (!type || !Type::GetByName("DynamicObject")->IsAssignableFrom(type)) - BOOST_THROW_EXCEPTION(ConfigError("Type '" + GetType() + "' does not exist.")); + ASSERT(type && Type::GetByName("DynamicObject")->IsAssignableFrom(type)); if (IsAbstract()) return DynamicObject::Ptr(); @@ -156,6 +154,7 @@ DynamicObject::Ptr ConfigItem::Commit(bool discard) locals->Set("name", m_Name); dobj->SetParentScope(locals); + locals.reset(); DebugHint debugHints; @@ -171,7 +170,7 @@ DynamicObject::Ptr ConfigItem::Commit(bool discard) if (discard) m_Expression.reset(); - dobj->SetParentScope(Dictionary::Ptr()); + dobj->SetParentScope(Object::Ptr()); String name = m_Name; @@ -199,6 +198,7 @@ DynamicObject::Ptr ConfigItem::Commit(bool discard) persistentItem->Set("debug_hints", debugHints.ToDictionary()); ConfigCompilerContext::GetInstance()->WriteObject(persistentItem); + persistentItem.reset(); ConfigType::Ptr ctype = ConfigType::GetByName(GetType()); diff --git a/lib/config/configitem.hpp b/lib/config/configitem.hpp index 51a74fccc..b3b1ad7dd 100644 --- a/lib/config/configitem.hpp +++ b/lib/config/configitem.hpp @@ -71,8 +71,6 @@ private: bool m_Abstract; /**< Whether this is a template. */ boost::shared_ptr m_Expression; - std::vector m_ParentNames; /**< The names of parent configuration - items. */ DebugInfo m_DebugInfo; /**< Debug information. */ Object::Ptr m_Scope; /**< variable scope. */ String m_Zone; /**< The zone. */ diff --git a/lib/config/configtype.cpp b/lib/config/configtype.cpp index 235331245..dcd07d9c2 100644 --- a/lib/config/configtype.cpp +++ b/lib/config/configtype.cpp @@ -68,8 +68,6 @@ void ConfigType::AddParentRules(std::vector& ruleLists, const if (parent) { AddParentRules(ruleLists, parent); - - ObjectLock plock(parent); ruleLists.push_back(parent->m_RuleList); } }