diff --git a/components/checker/checkercomponent.cpp b/components/checker/checkercomponent.cpp index 4adbda657..6b4ab546e 100644 --- a/components/checker/checkercomponent.cpp +++ b/components/checker/checkercomponent.cpp @@ -59,14 +59,17 @@ void CheckerComponent::CheckTimerHandler(void) double now = Utility::GetTime(); long tasks = 0; - while (!m_Services.empty()) { - CheckerComponent::ServiceMultiSet::iterator it = m_Services.begin(); + while (!m_IdleServices.empty()) { + typedef nth_index::type CheckTimeView; + CheckTimeView& idx = boost::get<1>(m_IdleServices); + + CheckTimeView::iterator it = idx.begin(); Service::Ptr service = *it; if (service->GetNextCheck() > now) break; - m_Services.erase(it); + idx.erase(it); Logger::Write(LogDebug, "checker", "Executing service check for '" + service->GetName() + "'"); @@ -130,11 +133,11 @@ void CheckerComponent::CheckCompletedHandler(const Service::Ptr& service, const /* remove the service from the list of pending services; if it's not in the * list this was a manual (i.e. forced) check and we must not re-add the * service to the services list because it's already there. */ - CheckerComponent::ServiceMultiSet::iterator it; + CheckerComponent::ServiceSet::iterator it; it = m_PendingServices.find(service); if (it != m_PendingServices.end()) { m_PendingServices.erase(it); - m_Services.insert(service); + m_IdleServices.insert(service); } Logger::Write(LogDebug, "checker", "Check finished for service '" + service->GetName() + "'"); @@ -145,7 +148,7 @@ void CheckerComponent::ResultTimerHandler(void) Logger::Write(LogDebug, "checker", "ResultTimerHandler entered."); stringstream msgbuf; - msgbuf << "Pending services: " << m_PendingServices.size() << "; Idle services: " << m_Services.size(); + msgbuf << "Pending services: " << m_PendingServices.size() << "; Idle services: " << m_IdleServices.size(); Logger::Write(LogInformation, "checker", msgbuf.str()); } @@ -159,9 +162,9 @@ void CheckerComponent::CheckerChangedHandler(const Service::Ptr& service) service->UpdateNextCheck(); - m_Services.insert(service); + m_IdleServices.insert(service); } else { - m_Services.erase(service); + m_IdleServices.erase(service); m_PendingServices.erase(service); } } @@ -174,7 +177,7 @@ void CheckerComponent::ServiceRemovedHandler(const DynamicObject::Ptr& object) if (!service) return; - m_Services.erase(service); + m_IdleServices.erase(service); m_PendingServices.erase(service); } diff --git a/components/checker/checkercomponent.h b/components/checker/checkercomponent.h index d5b18c464..8e59f6131 100644 --- a/components/checker/checkercomponent.h +++ b/components/checker/checkercomponent.h @@ -23,12 +23,13 @@ namespace icinga { -struct ServiceNextCheckLessComparer +struct ServiceNextCheckExtractor { -public: - bool operator()(const Service::Ptr& a, const Service::Ptr& b) + typedef double result_type; + + double operator()(const Service::Ptr& service) { - return a->GetNextCheck() > b->GetNextCheck(); + return service->GetNextCheck(); } }; @@ -41,7 +42,13 @@ public: typedef shared_ptr Ptr; typedef weak_ptr WeakPtr; - typedef multiset ServiceMultiSet; + typedef multi_index_container< + Service::Ptr, + indexed_by< + ordered_unique >, + ordered_non_unique + > + > ServiceSet; virtual void Start(void); virtual void Stop(void); @@ -49,8 +56,8 @@ public: private: VirtualEndpoint::Ptr m_Endpoint; - ServiceMultiSet m_Services; - ServiceMultiSet m_PendingServices; + ServiceSet m_IdleServices; + ServiceSet m_PendingServices; Timer::Ptr m_CheckTimer; diff --git a/components/checker/i2-checker.h b/components/checker/i2-checker.h index b142c84d6..4cb465d99 100644 --- a/components/checker/i2-checker.h +++ b/components/checker/i2-checker.h @@ -30,9 +30,16 @@ #include #include -#include +#include +#include +#include -using std::priority_queue; +using boost::multi_index_container; +using boost::multi_index::indexed_by; +using boost::multi_index::identity; +using boost::multi_index::ordered_unique; +using boost::multi_index::ordered_non_unique; +using boost::multi_index::nth_index; #include "checkercomponent.h"