summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-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;