diff options
Diffstat (limited to 'Swiften/EventLoop/EventLoop.cpp')
-rw-r--r-- | Swiften/EventLoop/EventLoop.cpp | 21 |
1 files changed, 12 insertions, 9 deletions
diff --git a/Swiften/EventLoop/EventLoop.cpp b/Swiften/EventLoop/EventLoop.cpp index d9a9081..b613645 100644 --- a/Swiften/EventLoop/EventLoop.cpp +++ b/Swiften/EventLoop/EventLoop.cpp @@ -12,12 +12,13 @@ #include <boost/bind.hpp> #include <boost/lambda/bind.hpp> #include <boost/lambda/lambda.hpp> #include <boost/optional.hpp> #include <boost/thread/locks.hpp> +#include <Swiften/Base/foreach.h> #include <Swiften/Base/Log.h> namespace lambda = boost::lambda; namespace Swift { @@ -37,31 +38,33 @@ inline void invokeCallback(const Event& event) { EventLoop::EventLoop() : nextEventID_(0) { } EventLoop::~EventLoop() { } -void EventLoop::handleNextEvent() { +void EventLoop::handleNextEvents() { + const int eventsBatched = 100; bool callEventPosted = false; { boost::recursive_mutex::scoped_lock lock(removeEventsMutex_); { - boost::optional<Event> nextEvent; + std::vector<Event> nextEvents; { - boost::recursive_mutex::scoped_lock lock(eventsMutex_); - if (!events_.empty()) { - nextEvent = events_.front(); + boost::recursive_mutex::scoped_lock lock(eventsMutex_); + for (int n = 0; ((n < eventsBatched) && !events_.empty()); n++) { + nextEvents.push_back(events_.front()); events_.pop_front(); } + callEventPosted = !events_.empty(); } - callEventPosted = !events_.empty(); - if (nextEvent) { - invokeCallback(nextEvent.get()); + if (!nextEvents.empty()) { + foreach (const Event& event, nextEvents) { + invokeCallback(event); + } } } - } if (callEventPosted) { eventPosted(); } } |