[icinga-checkins] icinga.org: icinga2/master: Checker: Use Ptrs rather than WeakPtrs.

git at icinga.org git at icinga.org
Tue Feb 26 10:59:07 CET 2013


Module: icinga2
Branch: master
Commit: 45f8bfb7306dfa29dbe78c7913a33f7de8066675
URL:    https://git.icinga.org/?p=icinga2.git;a=commit;h=45f8bfb7306dfa29dbe78c7913a33f7de8066675

Author: Gunnar Beutner <gunnar.beutner at netways.de>
Date:   Tue Feb 26 10:58:32 2013 +0100

Checker: Use Ptrs rather than WeakPtrs.

Fixes #3732

---

 components/checker/checkercomponent.cpp |    4 ++--
 components/checker/checkercomponent.h   |   11 +++--------
 lib/base/dynamicobject.cpp              |   12 ++++++++++--
 lib/base/dynamicobject.h                |    2 ++
 4 files changed, 17 insertions(+), 12 deletions(-)

diff --git a/components/checker/checkercomponent.cpp b/components/checker/checkercomponent.cpp
index 4ac847a..69dcfd7 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 f4f5704..9170d04 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<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;
diff --git a/lib/base/dynamicobject.cpp b/lib/base/dynamicobject.cpp
index bf30a33..d0f3638 100644
--- a/lib/base/dynamicobject.cpp
+++ b/lib/base/dynamicobject.cpp
@@ -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&)
 { }
diff --git a/lib/base/dynamicobject.h b/lib/base/dynamicobject.h
index a9031cb..1c63898 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<String> m_Source;
 	Attribute<Dictionary::Ptr> m_Methods;
 
+	bool m_Registered;
 	bool m_EventSafe;
 
 	static double m_CurrentTx;





More information about the icinga-checkins mailing list