diff options
-rw-r--r-- | Swiften/EventLoop/Cocoa/CocoaEventLoop.mm | 2 | ||||
-rw-r--r-- | Swiften/EventLoop/DummyEventLoop.cpp | 2 | ||||
-rw-r--r-- | Swiften/EventLoop/EventLoop.cpp | 21 | ||||
-rw-r--r-- | Swiften/EventLoop/EventLoop.h | 7 | ||||
-rw-r--r-- | Swiften/EventLoop/Qt/QtEventLoop.h | 2 | ||||
-rw-r--r-- | Swiften/EventLoop/SimpleEventLoop.cpp | 2 | ||||
-rw-r--r-- | Swiften/EventLoop/SingleThreadedEventLoop.cpp | 2 |
7 files changed, 21 insertions, 17 deletions
diff --git a/Swiften/EventLoop/Cocoa/CocoaEventLoop.mm b/Swiften/EventLoop/Cocoa/CocoaEventLoop.mm index 88da262..2d7c613 100644 --- a/Swiften/EventLoop/Cocoa/CocoaEventLoop.mm +++ b/Swiften/EventLoop/Cocoa/CocoaEventLoop.mm @@ -20,13 +20,13 @@ CocoaEventLoop::~CocoaEventLoop() { void CocoaEventLoop::handleNextCocoaEvent() { { boost::recursive_mutex::scoped_lock lock(isEventInCocoaEventLoopMutex_); isEventInCocoaEventLoop_ = false; } - handleNextEvent(); + handleNextEvents(); } void CocoaEventLoop::eventPosted() { boost::recursive_mutex::scoped_lock lock(isEventInCocoaEventLoopMutex_); if (!isEventInCocoaEventLoop_) { isEventInCocoaEventLoop_ = true; diff --git a/Swiften/EventLoop/DummyEventLoop.cpp b/Swiften/EventLoop/DummyEventLoop.cpp index 3675ead..45e9af7 100644 --- a/Swiften/EventLoop/DummyEventLoop.cpp +++ b/Swiften/EventLoop/DummyEventLoop.cpp @@ -19,13 +19,13 @@ DummyEventLoop::~DummyEventLoop() { } } void DummyEventLoop::processEvents() { while(hasEvents()) { hasEvents_ = false; - handleNextEvent(); + handleNextEvents(); } } bool DummyEventLoop::hasEvents() { boost::lock_guard<boost::mutex> lock(hasEventsMutex_); return hasEvents_; 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(); } } diff --git a/Swiften/EventLoop/EventLoop.h b/Swiften/EventLoop/EventLoop.h index 54e0fe7..27a8c9c 100644 --- a/Swiften/EventLoop/EventLoop.h +++ b/Swiften/EventLoop/EventLoop.h @@ -40,22 +40,23 @@ namespace Swift { * event queue. */ void removeEventsFromOwner(boost::shared_ptr<EventOwner> owner); protected: /** - * The \ref handleNextEvent method is called by an implementation of the abstract \ref EventLoop class + * The \ref handleNextEvents method is called by an implementation of the abstract \ref EventLoop class * at any point after the virtual \ref eventPosted method has been called. * This method does not block, except for short-time synchronization. + * It can process multiple events before it reutrns. */ - void handleNextEvent(); + void handleNextEvents(); /** * The \ref eventPosted virtual method serves as notification for when events are still available in the queue. * It is called after the first event is posted to an empty queue or after an event has been handled in - * \ref handleNextEvent and there are still remaining events in the queue. + * \ref handleNextEvents and there are still remaining events in the queue. */ virtual void eventPosted() = 0; private: unsigned int nextEventID_; std::list<Event> events_; diff --git a/Swiften/EventLoop/Qt/QtEventLoop.h b/Swiften/EventLoop/Qt/QtEventLoop.h index 389b0a7..123b6e8 100644 --- a/Swiften/EventLoop/Qt/QtEventLoop.h +++ b/Swiften/EventLoop/Qt/QtEventLoop.h @@ -35,13 +35,13 @@ namespace Swift { Event* event = dynamic_cast<Event*>(qevent); if (event) { { boost::recursive_mutex::scoped_lock lock(isEventInQtEventLoopMutex_); isEventInQtEventLoop_ = false; } - handleNextEvent(); + handleNextEvents(); //event->deleteLater(); FIXME: Leak? return true; } return false; } diff --git a/Swiften/EventLoop/SimpleEventLoop.cpp b/Swiften/EventLoop/SimpleEventLoop.cpp index 0bc06c9..59e799f 100644 --- a/Swiften/EventLoop/SimpleEventLoop.cpp +++ b/Swiften/EventLoop/SimpleEventLoop.cpp @@ -33,13 +33,13 @@ void SimpleEventLoop::doRun(bool breakAfterEvents) { return; } } } void SimpleEventLoop::runOnce() { - handleNextEvent(); + handleNextEvents(); } void SimpleEventLoop::stop() { postEvent(boost::bind(&SimpleEventLoop::doStop, this)); } diff --git a/Swiften/EventLoop/SingleThreadedEventLoop.cpp b/Swiften/EventLoop/SingleThreadedEventLoop.cpp index 095b962..d617534 100644 --- a/Swiften/EventLoop/SingleThreadedEventLoop.cpp +++ b/Swiften/EventLoop/SingleThreadedEventLoop.cpp @@ -35,13 +35,13 @@ void SingleThreadedEventLoop::waitForEvents() { void SingleThreadedEventLoop::handleEvents() { { boost::lock_guard<boost::mutex> lock(eventAvailableMutex_); eventAvailable_ = false; } - handleNextEvent(); + handleNextEvents(); } void SingleThreadedEventLoop::stop() { boost::unique_lock<boost::mutex> lock(eventAvailableMutex_); shouldShutDown_ = true; eventAvailableCondition_.notify_one(); |