]> granicus.if.org Git - icinga2/commitdiff
Clean up the code a bit
authorGunnar Beutner <gunnar@beutner.name>
Tue, 11 Nov 2014 22:06:47 +0000 (23:06 +0100)
committerGunnar Beutner <gunnar@beutner.name>
Tue, 11 Nov 2014 22:06:47 +0000 (23:06 +0100)
lib/base/dynamictype.cpp
lib/base/object.cpp
lib/base/object.hpp
lib/base/thinmutex.hpp
lib/config/configitem.cpp
lib/config/configitem.hpp
lib/config/configtype.cpp

index d20d83de60b2c32138055c2a57f314cb7c9f02d4..9d7adabbe43bf2ccc257669468da2a799ce33955 100644 (file)
@@ -28,7 +28,9 @@ using namespace icinga;
 
 DynamicType::DynamicType(const String& name)
        : m_Name(name)
-{ }
+{
+       InflateMutex();
+}
 
 DynamicType::Ptr DynamicType::GetByName(const String& name)
 {
index eba735b37eede8e0fb9d384802173bd7564bb346..b36bd4a59683677ff3e857e68e8e041a30f577dc 100644 (file)
@@ -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."));
index bfb8fe5c4e77a020291baff1f0309f5634638450..2b6bb8c93a865d3dd940b818ce180590d46687c6 100644 (file)
@@ -99,6 +99,8 @@ public:
        bool OwnsLock(void) const;
 #endif /* _DEBUG */
 
+       void InflateMutex(void);
+
 private:
        Object(const Object& other);
        Object& operator=(const Object& rhs);
index ab85ef37f4cc60ed456d4af8f4688288513ec6db..b600293f7f2936a1f6565f5a1265103c67686904 100644 (file)
@@ -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
index 53ac6e31711b05e44e7cdbd5d5f895fc1c98729a..26be1d8a325d629a6a48d4eede3cbf855b65ec86 100644 (file)
@@ -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());
 
index 51a74fcccf7ccb036c07c733f2cc1764c46a12a1..b3b1ad7ddd8009127758e4db363c0dd9833e9d2c 100644 (file)
@@ -71,8 +71,6 @@ private:
        bool m_Abstract; /**< Whether this is a template. */
 
        boost::shared_ptr<Expression> m_Expression;
-       std::vector<String> m_ParentNames; /**< The names of parent configuration
-                                      items. */
        DebugInfo m_DebugInfo; /**< Debug information. */
        Object::Ptr m_Scope; /**< variable scope. */
        String m_Zone; /**< The zone. */
index 235331245c7d667176264d9fea25672cf1a3a57b..dcd07d9c2cabc581436a6e451b568cef87f59e80 100644 (file)
@@ -68,8 +68,6 @@ void ConfigType::AddParentRules(std::vector<TypeRuleList::Ptr>& ruleLists, const
 
        if (parent) {
                AddParentRules(ruleLists, parent);
-
-               ObjectLock plock(parent);
                ruleLists.push_back(parent->m_RuleList);
        }
 }