diff options
author | Tobias Markmann <tm@ayena.de> | 2015-11-23 12:27:02 (GMT) |
---|---|---|
committer | Swift Review <review@swift.im> | 2015-12-17 18:30:00 (GMT) |
commit | 54b1a705c192c1c0afa3c71db393a275f25fc7ca (patch) | |
tree | 74c13bbf56cd4d8efd59c6f05015f0fc20825f0c /Swiften/EventLoop/EventLoop.cpp | |
parent | 29e8802886c0cb881e08a60cf0ea104e67577253 (diff) | |
download | swift-54b1a705c192c1c0afa3c71db393a275f25fc7ca.zip swift-54b1a705c192c1c0afa3c71db393a275f25fc7ca.tar.bz2 |
Process multiple events at once inside EventLoop
Test-Information:
Unit and integration tests pass on OS X 10.10.5 and Debian 8.2.
UI remains responsive when transferring a file between two
Swift instances.
Change-Id: I7841347a5d6c55121e02e274a7087a2fc200f879
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(); } } |