From: Gunnar Beutner Date: Tue, 26 Feb 2013 09:58:32 +0000 (+0100) Subject: Checker: Use Ptrs rather than WeakPtrs. X-Git-Tag: v0.0.2~363 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=45f8bfb7306dfa29dbe78c7913a33f7de8066675;p=icinga2 Checker: Use Ptrs rather than WeakPtrs. Fixes #3732 --- diff --git a/components/checker/checkercomponent.cpp b/components/checker/checkercomponent.cpp index 4ac847a9c..69dcfd7f6 100644 --- a/components/checker/checkercomponent.cpp +++ b/components/checker/checkercomponent.cpp @@ -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; } diff --git a/components/checker/checkercomponent.h b/components/checker/checkercomponent.h index f4f5704e0..9170d0498 100644 --- a/components/checker/checkercomponent.h +++ b/components/checker/checkercomponent.h @@ -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 WeakPtr; typedef multi_index_container< - Service::WeakPtr, + Service::Ptr, indexed_by< - ordered_unique >, + ordered_unique >, ordered_non_unique > > ServiceSet; diff --git a/lib/base/dynamicobject.cpp b/lib/base/dynamicobject.cpp index bf30a339a..d0f363885 100644 --- a/lib/base/dynamicobject.cpp +++ b/lib/base/dynamicobject.cpp @@ -33,7 +33,7 @@ signals2::signal&)> DynamicObjec signals2::signal 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&) { } diff --git a/lib/base/dynamicobject.h b/lib/base/dynamicobject.h index a9031cbfe..1c638981c 100644 --- a/lib/base/dynamicobject.h +++ b/lib/base/dynamicobject.h @@ -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 m_Source; Attribute m_Methods; + bool m_Registered; bool m_EventSafe; static double m_CurrentTx;