mirror of https://github.com/Icinga/icinga2.git
Bugfix: Unlock thread mutex while waiting for events.
This commit is contained in:
parent
d0481ea578
commit
172938b19d
|
@ -124,7 +124,7 @@ bool Application::ProcessEvents(void)
|
||||||
if (m_ShuttingDown)
|
if (m_ShuttingDown)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
GetEQ().ProcessEvents(boost::posix_time::milliseconds(sleep * 1000));
|
GetEQ().ProcessEvents(m_Mutex, boost::posix_time::milliseconds(sleep * 1000));
|
||||||
|
|
||||||
DynamicObject::FlushTx();
|
DynamicObject::FlushTx();
|
||||||
|
|
||||||
|
|
|
@ -46,24 +46,33 @@ void EventQueue::Stop(void)
|
||||||
* Waits for events using the specified timeout value and processes
|
* Waits for events using the specified timeout value and processes
|
||||||
* them.
|
* them.
|
||||||
*
|
*
|
||||||
|
* @param mtx The mutex that should be unlocked while waiting. Caller
|
||||||
|
* must have this mutex locked.
|
||||||
* @param timeout The wait timeout.
|
* @param timeout The wait timeout.
|
||||||
* @returns false if the queue has been stopped, true otherwise.
|
* @returns false if the queue has been stopped, true otherwise.
|
||||||
*/
|
*/
|
||||||
bool EventQueue::ProcessEvents(millisec timeout)
|
bool EventQueue::ProcessEvents(boost::mutex& mtx, millisec timeout)
|
||||||
{
|
{
|
||||||
vector<Callback> events;
|
vector<Callback> events;
|
||||||
|
|
||||||
|
mtx.unlock();
|
||||||
|
|
||||||
{
|
{
|
||||||
boost::mutex::scoped_lock lock(m_Mutex);
|
boost::mutex::scoped_lock lock(m_Mutex);
|
||||||
|
|
||||||
while (m_Events.empty() && !m_Stopped) {
|
while (m_Events.empty() && !m_Stopped) {
|
||||||
if (!m_EventAvailable.timed_wait(lock, timeout))
|
if (!m_EventAvailable.timed_wait(lock, timeout)) {
|
||||||
|
mtx.lock();
|
||||||
|
|
||||||
return !m_Stopped;
|
return !m_Stopped;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
events.swap(m_Events);
|
events.swap(m_Events);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mtx.lock();
|
||||||
|
|
||||||
BOOST_FOREACH(const Callback& ev, events) {
|
BOOST_FOREACH(const Callback& ev, events) {
|
||||||
double st = Utility::GetTime();
|
double st = Utility::GetTime();
|
||||||
|
|
||||||
|
@ -100,4 +109,3 @@ void EventQueue::Post(const EventQueue::Callback& callback)
|
||||||
m_EventAvailable.notify_all();
|
m_EventAvailable.notify_all();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -35,7 +35,7 @@ public:
|
||||||
|
|
||||||
EventQueue(void);
|
EventQueue(void);
|
||||||
|
|
||||||
bool ProcessEvents(millisec timeout = boost::posix_time::milliseconds(30000));
|
bool ProcessEvents(boost::mutex& mtx, millisec timeout = boost::posix_time::milliseconds(30000));
|
||||||
void Post(const Callback& callback);
|
void Post(const Callback& callback);
|
||||||
|
|
||||||
void Stop(void);
|
void Stop(void);
|
||||||
|
@ -43,6 +43,8 @@ public:
|
||||||
boost::thread::id GetOwner(void) const;
|
boost::thread::id GetOwner(void) const;
|
||||||
void SetOwner(boost::thread::id owner);
|
void SetOwner(boost::thread::id owner);
|
||||||
|
|
||||||
|
boost::mutex& GetMutex(void);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
boost::thread::id m_Owner;
|
boost::thread::id m_Owner;
|
||||||
|
|
||||||
|
|
|
@ -55,8 +55,12 @@ void ScriptInterpreter::ThreadWorkerProc(void)
|
||||||
{
|
{
|
||||||
m_EQ.SetOwner(boost::this_thread::get_id());
|
m_EQ.SetOwner(boost::this_thread::get_id());
|
||||||
|
|
||||||
while (m_EQ.ProcessEvents())
|
{
|
||||||
|
boost::mutex::scoped_lock lock(m_Mutex);
|
||||||
|
|
||||||
|
while (m_EQ.ProcessEvents(m_Mutex))
|
||||||
; /* empty loop */
|
; /* empty loop */
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScriptInterpreter::ScriptFunctionThunk(const ScriptTask::Ptr& task,
|
void ScriptInterpreter::ScriptFunctionThunk(const ScriptTask::Ptr& task,
|
||||||
|
|
|
@ -49,6 +49,7 @@ protected:
|
||||||
void UnsubscribeFunction(const String& name);
|
void UnsubscribeFunction(const String& name);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
boost::mutex m_Mutex;
|
||||||
EventQueue m_EQ;
|
EventQueue m_EQ;
|
||||||
set<String> m_SubscribedFunctions;
|
set<String> m_SubscribedFunctions;
|
||||||
boost::thread m_Thread;
|
boost::thread m_Thread;
|
||||||
|
|
Loading…
Reference in New Issue