]> granicus.if.org Git - icinga2/commitdiff
Checker: Use Ptrs rather than WeakPtrs.
authorGunnar Beutner <gunnar.beutner@netways.de>
Tue, 26 Feb 2013 09:58:32 +0000 (10:58 +0100)
committerGunnar Beutner <gunnar.beutner@netways.de>
Tue, 26 Feb 2013 09:58:32 +0000 (10:58 +0100)
Fixes #3732

components/checker/checkercomponent.cpp
components/checker/checkercomponent.h
lib/base/dynamicobject.cpp
lib/base/dynamicobject.h

index 4ac847a9c263a992d11d4eb653e0a2b5e1e3f460..69dcfd7f63759dc700e671f7ab1fcbdd091e8d0b 100644 (file)
@@ -72,9 +72,9 @@ void CheckerComponent::CheckThreadProc(void)
                        break;
 
                CheckTimeView::iterator it = idx.begin();
-               Service::Ptr service = it->lock();
+               Service::Ptr service = *it;
 
-               if (!service) {
+               if (!service->IsRegistered()) {
                        idx.erase(it);
                        continue;
                }
index f4f5704e04213b4c4bfb738ab9b305b5cdaac17c..9170d0498803f92c2f7475730ccf6be7362951de 100644 (file)
@@ -33,13 +33,8 @@ struct ServiceNextCheckExtractor
        /**
         * @threadsafety Caller must hold the mutex for the service.
         */
-       double operator()(const Service::WeakPtr& wservice)
+       double operator()(const Service::Ptr& service)
        {
-               Service::Ptr service = wservice.lock();
-
-               if (!service)
-                       return 0;
-
                return service->GetNextCheck();
        }
 };
@@ -54,9 +49,9 @@ public:
        typedef weak_ptr<CheckerComponent> WeakPtr;
 
        typedef multi_index_container<
-               Service::WeakPtr,
+               Service::Ptr,
                indexed_by<
-                       ordered_unique<identity<Service::WeakPtr> >,
+                       ordered_unique<identity<Service::Ptr> >,
                        ordered_non_unique<ServiceNextCheckExtractor>
                >
        > ServiceSet;
index bf30a339ab55acddd082efc83f4f5c11490cabf7..d0f3638852e97a953443b9fa44dac0bc8b8e8b1c 100644 (file)
@@ -33,7 +33,7 @@ signals2::signal<void (double, const set<DynamicObject::WeakPtr>&)> DynamicObjec
 signals2::signal<void (const DynamicObject::Ptr&)> DynamicObject::OnFlushObject;
 
 DynamicObject::DynamicObject(const Dictionary::Ptr& serializedObject)
-       : m_EventSafe(false), m_ConfigTx(0)
+       : m_EventSafe(false), m_ConfigTx(0), m_Registered(false)
 {
        RegisterAttribute("__name", Attribute_Config, &m_Name);
        RegisterAttribute("__type", Attribute_Config, &m_Type);
@@ -309,6 +309,11 @@ bool DynamicObject::IsAbstract(void) const
        return m_Abstract;
 }
 
+bool DynamicObject::IsRegistered(void) const
+{
+       return m_Registered;
+}
+
 void DynamicObject::SetSource(const String& value)
 {
        m_Source = value;
@@ -572,7 +577,10 @@ void DynamicObject::OnConstructionCompleted(void)
 }
 
 void DynamicObject::OnRegistrationCompleted(void)
-{ }
+{
+       ObjectLock olock(this);
+       m_Registered = true;
+}
 
 void DynamicObject::OnAttributeChanged(const String&, const Value&)
 { }
index a9031cbfe7ea85597641f7aab9b807b3f4747ba1..1c638981c94aa0339353a02e97ff43615aaa5e90 100644 (file)
@@ -238,6 +238,7 @@ public:
 
        bool IsLocal(void) const;
        bool IsAbstract(void) const;
+       bool IsRegistered(void) const;
 
        void SetSource(const String& value);
        String GetSource(void) const;
@@ -286,6 +287,7 @@ private:
        Attribute<String> m_Source;
        Attribute<Dictionary::Ptr> m_Methods;
 
+       bool m_Registered;
        bool m_EventSafe;
 
        static double m_CurrentTx;