[icinga-checkins] icinga.org: icinga2/master: Checker: Use weak_ptrs to keep track of services.

git at icinga.org git at icinga.org
Mon Feb 11 13:05:22 CET 2013


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

Author: Gunnar Beutner <gunnar.beutner at netways.de>
Date:   Mon Feb 11 13:05:08 2013 +0100

Checker: Use weak_ptrs to keep track of services.

---

 components/checker/checkercomponent.cpp |   22 +++++++++++++++++++---
 components/checker/checkercomponent.h   |   11 ++++++++---
 2 files changed, 27 insertions(+), 6 deletions(-)

diff --git a/components/checker/checkercomponent.cpp b/components/checker/checkercomponent.cpp
index 3c731f3..12b3bad 100644
--- a/components/checker/checkercomponent.cpp
+++ b/components/checker/checkercomponent.cpp
@@ -63,7 +63,12 @@ void CheckerComponent::CheckTimerHandler(void)
 		CheckTimeView& idx = boost::get<1>(m_IdleServices);
 
 		CheckTimeView::iterator it = idx.begin();
-		Service::Ptr service = *it;
+		Service::Ptr service = it->lock();
+
+		if (!service) {
+			idx.erase(it);
+			continue;
+		}
 
 		if (service->GetNextCheck() > now)
 			break;
@@ -206,8 +211,19 @@ void CheckerComponent::RescheduleCheckTimer(void)
 	typedef nth_index<ServiceSet, 1>::type CheckTimeView;
 	CheckTimeView& idx = boost::get<1>(m_IdleServices);
 
-	CheckTimeView::iterator it = idx.begin();
-	Service::Ptr service = *it;
+	Service::Ptr service;
+
+	do {
+		CheckTimeView::iterator it = idx.begin();
+
+		if (it == idx.end())
+			return;
+
+		service = it->lock();
+
+		if (!service)
+			idx.erase(it);
+	} while (!service);
 
 	m_CheckTimer->Reschedule(service->GetNextCheck());
 }
diff --git a/components/checker/checkercomponent.h b/components/checker/checkercomponent.h
index a6f6527..f930fa0 100644
--- a/components/checker/checkercomponent.h
+++ b/components/checker/checkercomponent.h
@@ -30,8 +30,13 @@ struct ServiceNextCheckExtractor
 {
 	typedef double result_type;
 
-	double operator()(const Service::Ptr& service)
+	double operator()(const Service::WeakPtr& wservice)
 	{
+		Service::Ptr service = wservice.lock();
+
+		if (!service)
+			return 0;
+
 		return service->GetNextCheck();
 	}
 };
@@ -46,9 +51,9 @@ public:
 	typedef weak_ptr<CheckerComponent> WeakPtr;
 
 	typedef multi_index_container<
-		Service::Ptr,
+		Service::WeakPtr,
 		indexed_by<
-			ordered_unique<identity<Service::Ptr> >,
+			ordered_unique<identity<Service::WeakPtr> >,
 			ordered_non_unique<ServiceNextCheckExtractor>
 		>
 	> ServiceSet;





More information about the icinga-checkins mailing list