Fix: Only take one work item from the event queue per iteration.

This commit is contained in:
Gunnar Beutner 2013-03-15 09:10:06 +01:00
parent 876519034c
commit 0f9acdffbb
3 changed files with 37 additions and 36 deletions

View File

@ -78,7 +78,7 @@ void EventQueue::Join(void)
void EventQueue::QueueThreadProc(void) void EventQueue::QueueThreadProc(void)
{ {
for (;;) { for (;;) {
vector<Callback> events; Callback event;
{ {
boost::mutex::scoped_lock lock(m_Mutex); boost::mutex::scoped_lock lock(m_Mutex);
@ -89,10 +89,10 @@ void EventQueue::QueueThreadProc(void)
if (m_Events.empty() && m_Stopped) if (m_Events.empty() && m_Stopped)
break; break;
events.swap(m_Events); event = m_Events.top();
m_Events.pop();
} }
BOOST_FOREACH(const Callback& ev, events) {
#ifdef _DEBUG #ifdef _DEBUG
double st = Utility::GetTime(); double st = Utility::GetTime();
@ -104,7 +104,7 @@ void EventQueue::QueueThreadProc(void)
#endif /* _DEBUG */ #endif /* _DEBUG */
try { try {
ev(); event();
} catch (const std::exception& ex) { } catch (const std::exception& ex) {
stringstream msgbuf; stringstream msgbuf;
msgbuf << "Exception thrown in event handler: " << std::endl msgbuf << "Exception thrown in event handler: " << std::endl
@ -146,7 +146,6 @@ void EventQueue::QueueThreadProc(void)
} }
#endif /* _DEBUG */ #endif /* _DEBUG */
} }
}
} }
/** /**
@ -158,7 +157,7 @@ void EventQueue::QueueThreadProc(void)
void EventQueue::Post(const EventQueue::Callback& callback) void EventQueue::Post(const EventQueue::Callback& callback)
{ {
boost::mutex::scoped_lock lock(m_Mutex); boost::mutex::scoped_lock lock(m_Mutex);
m_Events.push_back(callback); m_Events.push(callback);
m_CV.notify_one(); m_CV.notify_one();
} }

View File

@ -50,7 +50,7 @@ private:
condition_variable m_CV; condition_variable m_CV;
bool m_Stopped; bool m_Stopped;
vector<Callback> m_Events; stack<Callback> m_Events;
void QueueThreadProc(void); void QueueThreadProc(void);
void ReportThreadProc(void); void ReportThreadProc(void);

View File

@ -91,6 +91,7 @@
#include <list> #include <list>
#include <algorithm> #include <algorithm>
#include <deque> #include <deque>
#include <stack>
#include <iterator> #include <iterator>
using std::vector; using std::vector;
@ -101,6 +102,7 @@ using std::multimap;
using std::multiset; using std::multiset;
using std::pair; using std::pair;
using std::deque; using std::deque;
using std::stack;
using std::make_pair; using std::make_pair;
using std::stringstream; using std::stringstream;