mirror of https://github.com/Icinga/icinga2.git
Fix an issue where expired Timer pointers caused other timers to be delayed.
Fixes #6179
This commit is contained in:
parent
4c235f7785
commit
042e4270bf
|
@ -32,37 +32,17 @@
|
|||
|
||||
using namespace icinga;
|
||||
|
||||
/**
|
||||
* @ingroup base
|
||||
*/
|
||||
struct icinga::TimerNextExtractor
|
||||
struct TimerHolder
|
||||
{
|
||||
typedef double result_type;
|
||||
|
||||
/**
|
||||
* Extracts the next timestamp from a Timer.
|
||||
*
|
||||
* Note: Caller must hold l_Mutex.
|
||||
*
|
||||
* @param wtimer Weak pointer to the timer.
|
||||
* @returns The next timestamp
|
||||
*/
|
||||
double operator()(const weak_ptr<Timer>& wtimer) const
|
||||
{
|
||||
Timer::Ptr timer = wtimer.lock();
|
||||
|
||||
if (!timer)
|
||||
return 0;
|
||||
|
||||
return timer->m_Next;
|
||||
}
|
||||
Timer::WeakPtr Object;
|
||||
double Next;
|
||||
};
|
||||
|
||||
typedef boost::multi_index_container<
|
||||
Timer::WeakPtr,
|
||||
TimerHolder,
|
||||
boost::multi_index::indexed_by<
|
||||
boost::multi_index::ordered_unique<boost::multi_index::identity<Timer::WeakPtr> >,
|
||||
boost::multi_index::ordered_non_unique<TimerNextExtractor>
|
||||
boost::multi_index::ordered_unique<boost::multi_index::member<TimerHolder, Timer::WeakPtr, &TimerHolder::Object> >,
|
||||
boost::multi_index::ordered_non_unique<boost::multi_index::member<TimerHolder, double, &TimerHolder::Next> >
|
||||
>
|
||||
> TimerSet;
|
||||
|
||||
|
@ -205,7 +185,11 @@ void Timer::Reschedule(double next)
|
|||
if (m_Started) {
|
||||
/* Remove and re-add the timer to update the index. */
|
||||
l_Timers.erase(GetSelf());
|
||||
l_Timers.insert(GetSelf());
|
||||
|
||||
TimerHolder th;
|
||||
th.Object = GetSelf();
|
||||
th.Next = m_Next;
|
||||
l_Timers.insert(th);
|
||||
|
||||
/* Notify the worker that we've rescheduled a timer. */
|
||||
l_CV.notify_all();
|
||||
|
@ -242,8 +226,8 @@ void Timer::AdjustTimers(double adjustment)
|
|||
|
||||
std::vector<Timer::Ptr> timers;
|
||||
|
||||
BOOST_FOREACH(const Timer::WeakPtr& wtimer, idx) {
|
||||
Timer::Ptr timer = wtimer.lock();
|
||||
BOOST_FOREACH(const TimerHolder& th, idx) {
|
||||
Timer::Ptr timer = th.Object.lock();
|
||||
|
||||
if (!timer)
|
||||
continue;
|
||||
|
@ -257,7 +241,11 @@ void Timer::AdjustTimers(double adjustment)
|
|||
|
||||
BOOST_FOREACH(const Timer::Ptr& timer, timers) {
|
||||
l_Timers.erase(timer);
|
||||
l_Timers.insert(timer);
|
||||
|
||||
TimerHolder th;
|
||||
th.Object = timer;
|
||||
th.Next = timer->m_Next;
|
||||
l_Timers.insert(th);
|
||||
}
|
||||
|
||||
/* Notify the worker that we've rescheduled some timers. */
|
||||
|
@ -285,7 +273,7 @@ void Timer::TimerThreadProc(void)
|
|||
break;
|
||||
|
||||
NextTimerView::iterator it = idx.begin();
|
||||
Timer::Ptr timer = it->lock();
|
||||
Timer::Ptr timer = it->Object.lock();
|
||||
|
||||
if (!timer) {
|
||||
/* Remove the timer from the list if it's not alive anymore. */
|
||||
|
|
|
@ -26,8 +26,6 @@
|
|||
|
||||
namespace icinga {
|
||||
|
||||
struct TimerNextExtractor;
|
||||
|
||||
/**
|
||||
* A timer that periodically triggers an event.
|
||||
*
|
||||
|
|
|
@ -39,6 +39,8 @@ boost::signals2::signal<void (const Checkable::Ptr&, const Downtime::Ptr&, const
|
|||
boost::signals2::signal<void (const Checkable::Ptr&, const Downtime::Ptr&, const MessageOrigin&)> Checkable::OnDowntimeRemoved;
|
||||
boost::signals2::signal<void (const Checkable::Ptr&, const Downtime::Ptr&)> Checkable::OnDowntimeTriggered;
|
||||
|
||||
INITIALIZE_ONCE(&Checkable::StartDowntimesExpiredTimer);
|
||||
|
||||
int Checkable::GetNextDowntimeID(void)
|
||||
{
|
||||
boost::mutex::scoped_lock lock(l_DowntimeMutex);
|
||||
|
|
|
@ -37,8 +37,6 @@ using namespace icinga;
|
|||
|
||||
REGISTER_TYPE(Checkable);
|
||||
|
||||
INITIALIZE_ONCE(&Checkable::StartDowntimesExpiredTimer);
|
||||
|
||||
boost::signals2::signal<void (const Checkable::Ptr&, const String&, const String&, AcknowledgementType, double, const MessageOrigin&)> Checkable::OnAcknowledgementSet;
|
||||
boost::signals2::signal<void (const Checkable::Ptr&, const MessageOrigin&)> Checkable::OnAcknowledgementCleared;
|
||||
|
||||
|
|
|
@ -37,8 +37,6 @@ using namespace icinga;
|
|||
|
||||
REGISTER_TYPE(Service);
|
||||
|
||||
INITIALIZE_ONCE(&Service::StartDowntimesExpiredTimer);
|
||||
|
||||
String ServiceNameComposer::MakeName(const String& shortName, const Dictionary::Ptr props) const {
|
||||
if (!props)
|
||||
return "";
|
||||
|
|
|
@ -68,8 +68,8 @@ add_boost_test(base
|
|||
base_string/find
|
||||
base_timer/construct
|
||||
base_timer/interval
|
||||
# base_timer/invoke
|
||||
# base_timer/scope
|
||||
base_timer/invoke
|
||||
base_timer/scope
|
||||
base_value/scalar
|
||||
base_value/convert
|
||||
base_value/format
|
||||
|
|
|
@ -58,7 +58,7 @@ static void Callback(int *counter)
|
|||
(*counter)++;
|
||||
}
|
||||
|
||||
/*BOOST_AUTO_TEST_CASE(invoke)
|
||||
BOOST_AUTO_TEST_CASE(invoke)
|
||||
{
|
||||
int counter;
|
||||
Timer::Ptr timer = make_shared<Timer>();
|
||||
|
@ -87,6 +87,6 @@ BOOST_AUTO_TEST_CASE(scope)
|
|||
Utility::Sleep(5.5);
|
||||
|
||||
BOOST_CHECK(counter >= 4 && counter <= 6);
|
||||
}*/
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_SUITE_END()
|
||||
|
|
Loading…
Reference in New Issue