summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorThiago Macieira <thiago.macieira@nokia.com>2010-06-30 15:18:24 +0200
committerQt by Nokia <qt-info@nokia.com>2011-10-27 11:12:38 +0200
commita94c960b75453ef2eb9dca0be1db426de7a1091d (patch)
tree4db571c54a8f1e42353dced5920ecf11e7fc3d83 /src
parent0c3d898a03b675c942e5c8a798b54676d3edf3ae (diff)
Unix (non-Glib) event dispatcher: round sleep to millisecond boundary.
If we have two timers running in an application with the same timeout and started almost at the same time by the code, they would trigger two sleeps, the second of which very short (under a millisecond). This causes us to match the Glib and Windows event loops, which round all timers to millisecond anyway. Change-Id: I7eb531e02dadf75925c01192b0f33ef3641ae1ea Reviewed-by: Olivier Goffart <ogoffart@kde.org>
Diffstat (limited to 'src')
-rw-r--r--src/corelib/kernel/qeventdispatcher_unix.cpp16
1 files changed, 15 insertions, 1 deletions
diff --git a/src/corelib/kernel/qeventdispatcher_unix.cpp b/src/corelib/kernel/qeventdispatcher_unix.cpp
index f2f9dd6aaf..3c7a48ac68 100644
--- a/src/corelib/kernel/qeventdispatcher_unix.cpp
+++ b/src/corelib/kernel/qeventdispatcher_unix.cpp
@@ -441,6 +441,20 @@ void QTimerInfoList::timerRepair(const timeval &diff)
}
}
+static timeval roundToMillisecond(timeval val)
+{
+ // always round up
+ // worst case scenario is that the first trigger of a 1-ms timer is 0.999 ms late
+
+ int us = val.tv_usec % 1000;
+ val.tv_usec += 1000 - us;
+ if (val.tv_usec > 1000000) {
+ val.tv_usec -= 1000000;
+ ++val.tv_sec;
+ }
+ return val;
+}
+
/*
Returns the time to wait for the next timer, or null if no timers
are waiting.
@@ -464,7 +478,7 @@ bool QTimerInfoList::timerWait(timeval &tm)
if (currentTime < t->timeout) {
// time to wait
- tm = t->timeout - currentTime;
+ tm = roundToMillisecond(t->timeout - currentTime);
} else {
// no time to wait
tm.tv_sec = 0;