diff options
author | Bernd Weimer <bweimer@rim.com> | 2013-01-04 12:43:55 (GMT) |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-01-05 13:45:30 (GMT) |
commit | b36bf7507c02f0e3cf32abda49e295fdd94a4848 (patch) | |
tree | 68dfbf4eae4ec56b34d61fed85cb1159bebf30f5 | |
parent | 1261a0b330dd1a8261f7862835cc6e4704ac095f (diff) | |
download | Qt-b36bf7507c02f0e3cf32abda49e295fdd94a4848.zip Qt-b36bf7507c02f0e3cf32abda49e295fdd94a4848.tar.gz Qt-b36bf7507c02f0e3cf32abda49e295fdd94a4848.tar.bz2 |
BlackBerry: Reevaluation of timer list in event dispatcher
In the event dispatcher the timer list has to be reevaluated after
each call to filterEvent, because timers could be started in event
filters.
Backport of 9cfce43f19af87bc0a929b917da2901de7dbc193
Change-Id: Ib1feca6e970b3809e422f50164fd280b96beddf3
Reviewed-by: Sean Harmer <sean.harmer@kdab.com>
-rw-r--r-- | src/corelib/kernel/qeventdispatcher_blackberry.cpp | 33 |
1 files changed, 22 insertions, 11 deletions
diff --git a/src/corelib/kernel/qeventdispatcher_blackberry.cpp b/src/corelib/kernel/qeventdispatcher_blackberry.cpp index 0a8b0a6..394fde4 100644 --- a/src/corelib/kernel/qeventdispatcher_blackberry.cpp +++ b/src/corelib/kernel/qeventdispatcher_blackberry.cpp @@ -132,7 +132,7 @@ static int bpsIOHandler(int fd, int io_events, void *data) } // post unblock event to our thread; in this callback the bps channel is - // guarenteed to be the same that was active when bps_add_fd was called + // guaranteed to be the same that was active when bps_add_fd was called result = bps_push_event(event); if (result != BPS_SUCCESS) { qWarning("QEventDispatcherBlackberryPrivate::QEventDispatcherBlackberry: bps_push_event() failed"); @@ -271,6 +271,11 @@ void QEventDispatcherBlackberry::unregisterSocketNotifier(QSocketNotifier *notif } } +static inline int timevalToMillisecs(const timeval &tv) +{ + return (tv.tv_sec * 1000) + (tv.tv_usec / 1000); +} + int QEventDispatcherBlackberry::select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, timeval *timeout) { @@ -279,9 +284,6 @@ int QEventDispatcherBlackberry::select(int nfds, fd_set *readfds, fd_set *writef BpsChannelScopeSwitcher channelSwitcher(d->bps_channel); - // Make a note of the start time - timeval startTime = qt_gettime(); - // prepare file sets for bps callback d->ioData->count = 0; d->ioData->readfds = readfds; @@ -298,15 +300,15 @@ int QEventDispatcherBlackberry::select(int nfds, fd_set *readfds, fd_set *writef if (exceptfds) FD_ZERO(exceptfds); + bps_event_t *event = 0; + unsigned int eventCount = 0; + // Convert timeout to milliseconds int timeoutTotal = -1; if (timeout) - timeoutTotal = (timeout->tv_sec * 1000) + (timeout->tv_usec / 1000); - + timeoutTotal = timevalToMillisecs(*timeout); int timeoutLeft = timeoutTotal; - - bps_event_t *event = 0; - unsigned int eventCount = 0; + timeval startTime = qt_gettime(); // This loop exists such that we can drain the bps event queue of all native events // more efficiently than if we were to return control to Qt after each event. This @@ -331,11 +333,20 @@ int QEventDispatcherBlackberry::select(int nfds, fd_set *readfds, fd_set *writef // Clock source is monotonic, so we can recalculate how much timeout is left if (timeoutTotal != -1) { timeval t2 = qt_gettime(); - timeoutLeft = timeoutTotal - ((t2.tv_sec * 1000 + t2.tv_usec / 1000) - - (startTime.tv_sec * 1000 + startTime.tv_usec / 1000)); + timeoutLeft = timeoutTotal + - (timevalToMillisecs(t2) - timevalToMillisecs(startTime)); if (timeoutLeft < 0) timeoutLeft = 0; } + + timeval tnext; + if (d->timerList.timerWait(tnext)) { + int timeoutNext = timevalToMillisecs(tnext); + if (timeoutNext < timeoutLeft || timeoutTotal == -1) { + timeoutTotal = timeoutLeft = timeoutNext; + startTime = qt_gettime(); + } + } } // Wait for event or file to be ready |