Checker: Use weak_ptrs to keep track of services.

This commit is contained in:
Gunnar Beutner 2013-02-11 13:05:08 +01:00
parent 0e353c7b29
commit 4888a26c0e
2 changed files with 27 additions and 6 deletions

View File

@ -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());
}

View File

@ -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;