mirror of https://github.com/Icinga/icinga2.git
parent
9567cd663b
commit
d397933eff
|
@ -49,7 +49,7 @@ static TimerSet l_Timers;
|
|||
* Constructor for the Timer class.
|
||||
*/
|
||||
Timer::Timer(void)
|
||||
: m_Interval(0), m_Next(0)
|
||||
: m_Interval(0), m_Next(0), m_Started(false), m_Running(false)
|
||||
{ }
|
||||
|
||||
/**
|
||||
|
@ -58,6 +58,10 @@ Timer::Timer(void)
|
|||
Timer::~Timer(void)
|
||||
{
|
||||
Stop();
|
||||
|
||||
boost::mutex::scoped_lock lock(l_TimerMutex);
|
||||
while (m_Running)
|
||||
l_TimerCV.wait(lock);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -100,7 +104,14 @@ void Timer::Call(void)
|
|||
throw;
|
||||
}
|
||||
|
||||
{
|
||||
boost::mutex::scoped_lock lock(l_TimerMutex);
|
||||
m_Running = false;
|
||||
l_TimerCV.notify_all();
|
||||
}
|
||||
|
||||
Reschedule();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -172,6 +183,7 @@ void Timer::Stop(void)
|
|||
void Timer::Reschedule(double next)
|
||||
{
|
||||
ASSERT(!OwnsLock());
|
||||
ASSERT(!m_Running);
|
||||
|
||||
boost::mutex::scoped_lock lock(l_TimerMutex);
|
||||
|
||||
|
@ -280,6 +292,8 @@ void Timer::TimerThreadProc(void)
|
|||
* until the current call is completed. */
|
||||
l_Timers.erase(timer);
|
||||
|
||||
timer->m_Running = true;
|
||||
|
||||
lock.unlock();
|
||||
|
||||
/* Asynchronously call the timer. */
|
||||
|
|
|
@ -81,6 +81,7 @@ private:
|
|||
double m_Interval; /**< The interval of the timer. */
|
||||
double m_Next; /**< When the next event should happen. */
|
||||
bool m_Started; /**< Whether the timer is enabled. */
|
||||
bool m_Running; /**< Whether the timer proc is currently running. */
|
||||
|
||||
void Call();
|
||||
|
||||
|
|
Loading…
Reference in New Issue