if (m_ShuttingDown)
return false;
- GetEQ().ProcessEvents(boost::posix_time::milliseconds(sleep * 1000));
+ GetEQ().ProcessEvents(m_Mutex, boost::posix_time::milliseconds(sleep * 1000));
DynamicObject::FlushTx();
* Waits for events using the specified timeout value and processes
* them.
*
+ * @param mtx The mutex that should be unlocked while waiting. Caller
+ * must have this mutex locked.
* @param timeout The wait timeout.
* @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;
+ mtx.unlock();
+
{
boost::mutex::scoped_lock lock(m_Mutex);
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;
+ }
}
events.swap(m_Events);
}
+ mtx.lock();
+
BOOST_FOREACH(const Callback& ev, events) {
double st = Utility::GetTime();
m_EventAvailable.notify_all();
}
}
-
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 Stop(void);
boost::thread::id GetOwner(void) const;
void SetOwner(boost::thread::id owner);
+ boost::mutex& GetMutex(void);
+
private:
boost::thread::id m_Owner;
{
m_EQ.SetOwner(boost::this_thread::get_id());
- while (m_EQ.ProcessEvents())
- ; /* empty loop */
+ {
+ boost::mutex::scoped_lock lock(m_Mutex);
+
+ while (m_EQ.ProcessEvents(m_Mutex))
+ ; /* empty loop */
+ }
}
void ScriptInterpreter::ScriptFunctionThunk(const ScriptTask::Ptr& task,