From a1db305f482de2d24797b8f99a752e49e80fa392 Mon Sep 17 00:00:00 2001 From: axis Date: Tue, 19 May 2009 16:17:29 +0200 Subject: Made a small correction and optmization to the event dispatcher. By keeping record of the iteration count of the event loop, we can determine whether the active object being processed is being run for the first time or not in the current iteration. This is slightly faster, since it saves us from adding the AO to the deferred queue the second time around if the iteration is different. It is also slightly more correct, since otherwise running a timer twice would take three calls to processEvents instead of two (first time: run AO, second time: add to queue, third time: run AO from the queue). RevBy: Trust me AutoTest: Passed --- src/corelib/kernel/qeventdispatcher_symbian.cpp | 19 ++++++++++++++----- src/corelib/kernel/qeventdispatcher_symbian_p.h | 4 ++++ 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/src/corelib/kernel/qeventdispatcher_symbian.cpp b/src/corelib/kernel/qeventdispatcher_symbian.cpp index e1e3e0e..aca328a 100644 --- a/src/corelib/kernel/qeventdispatcher_symbian.cpp +++ b/src/corelib/kernel/qeventdispatcher_symbian.cpp @@ -98,7 +98,8 @@ inline QActiveObject::QActiveObject(TInt priority, QEventDispatcherSymbian *disp : CActive(priority), m_dispatcher(dispatcher), m_hasAlreadyRun(false), - m_hasRunAgain(false) + m_hasRunAgain(false), + m_iterationCount(1) { } @@ -112,13 +113,16 @@ bool QActiveObject::okToRun() { Q_ASSERT(!m_hasRunAgain); - if (m_hasAlreadyRun) { + if (!m_hasAlreadyRun || m_dispatcher->iterationCount() != m_iterationCount) { + // First occurrence of this event in this iteration. + m_hasAlreadyRun = true; + m_iterationCount = m_dispatcher->iterationCount(); + return true; + } else { + // The event has already occurred. m_dispatcher->addDeferredActiveObject(this); m_hasRunAgain = true; return false; - } else { - m_hasAlreadyRun = true; - return true; } } @@ -528,6 +532,7 @@ QEventDispatcherSymbian::QEventDispatcherSymbian(QObject *parent) m_completeDeferredAOs(0), m_interrupt(false), m_wakeUpDone(0), + m_iterationCount(0), m_noSocketEvents(false) { } @@ -566,6 +571,10 @@ bool QEventDispatcherSymbian::processEvents ( QEventLoop::ProcessEventsFlags fla { Q_D(QAbstractEventDispatcher); + // It is safe if this counter overflows. The main importance is that each + // iteration count is different from the last. + m_iterationCount++; + RThread &thread = d->threadData->symbian_thread_handle; bool block; diff --git a/src/corelib/kernel/qeventdispatcher_symbian_p.h b/src/corelib/kernel/qeventdispatcher_symbian_p.h index 3233fe4..393749f 100644 --- a/src/corelib/kernel/qeventdispatcher_symbian_p.h +++ b/src/corelib/kernel/qeventdispatcher_symbian_p.h @@ -61,6 +61,7 @@ protected: private: bool m_hasAlreadyRun : 1; bool m_hasRunAgain : 1; + int m_iterationCount; }; class QWakeUpActiveObject : public CActive @@ -207,6 +208,8 @@ public: void removeDeferredActiveObject(QActiveObject *object); void reactivateDeferredActiveObjects(); + inline int iterationCount() const { return m_iterationCount; } + static void RequestComplete(TRequestStatus *&status, TInt reason); static void RequestComplete(RThread &threadHandle, TRequestStatus *&status, TInt reason); @@ -228,6 +231,7 @@ private: volatile bool m_interrupt; QAtomicInt m_wakeUpDone; + unsigned char m_iterationCount; bool m_noSocketEvents; QList m_deferredSocketEvents; -- cgit v0.12