summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorNorwegian Rock Cat <qt-info@nokia.com>2009-07-20 08:08:52 (GMT)
committerNorwegian Rock Cat <qt-info@nokia.com>2009-07-20 08:08:52 (GMT)
commitf900b675047c2e595a270b2a65edf8a9731b252a (patch)
treed1e31f1bb7552218be920a5ccd7bf29e4817b99c /src
parent27a07955d796a9c2b52302ad7f5ce0cd9d6179e1 (diff)
downloadQt-f900b675047c2e595a270b2a65edf8a9731b252a.zip
Qt-f900b675047c2e595a270b2a65edf8a9731b252a.tar.gz
Qt-f900b675047c2e595a270b2a65edf8a9731b252a.tar.bz2
Get monotonic time working on Mac OS X for corelib programs.
Mac OS X does not provide POSIX monotonic timers. Instead it does provide a Mach call to get the absolute time (a.k.a., number of CPU ticks) for the next timer event. This gets us around the bug in select(2) on Mac, that it doesn't wakeup when the times been changed. Of course, if you used the GUI event dispatcher, which is based on CFRunLoopTimers, this is not an issue, but if you really just need corelib, it's a bear to bring in the other stuff. Thanks to the nice guys at Parallels for the basics of the patch! Task-number: 237384 Reviewed-by: Bradley T. Hughes
Diffstat (limited to 'src')
-rw-r--r--src/corelib/kernel/qeventdispatcher_unix.cpp23
1 files changed, 21 insertions, 2 deletions
diff --git a/src/corelib/kernel/qeventdispatcher_unix.cpp b/src/corelib/kernel/qeventdispatcher_unix.cpp
index 0eeea04..9deb78f 100644
--- a/src/corelib/kernel/qeventdispatcher_unix.cpp
+++ b/src/corelib/kernel/qeventdispatcher_unix.cpp
@@ -59,6 +59,10 @@
# include <sys/times.h>
#endif
+#ifdef Q_OS_MAC
+#include <mach/mach_time.h>
+#endif
+
QT_BEGIN_NAMESPACE
Q_CORE_EXPORT bool qt_disable_lowpriority_timers=false;
@@ -259,7 +263,7 @@ int QEventDispatcherUNIXPrivate::doSelect(QEventLoop::ProcessEventsFlags flags,
QTimerInfoList::QTimerInfoList()
{
-#if (_POSIX_MONOTONIC_CLOCK-0 <= 0)
+#if (_POSIX_MONOTONIC_CLOCK-0 <= 0) && !defined(Q_OS_MAC)
useMonotonicTimers = false;
# if (_POSIX_MONOTONIC_CLOCK == 0)
@@ -287,6 +291,9 @@ QTimerInfoList::QTimerInfoList()
msPerTick = 0;
}
#else
+# if defined(Q_OS_MAC)
+ useMonotonicTimers = true;
+# endif
// using monotonic timers unconditionally
getTime(currentTime);
#endif
@@ -335,7 +342,19 @@ bool QTimerInfoList::timeChanged(timeval *delta)
void QTimerInfoList::getTime(timeval &t)
{
-#if !defined(QT_NO_CLOCK_MONOTONIC) && !defined(QT_BOOTSTRAPPED)
+#if defined(Q_OS_MAC)
+ {
+ static mach_timebase_info_data_t info = {0,0};
+ if (info.denom == 0)
+ mach_timebase_info(&info);
+
+ uint64_t cpu_time = mach_absolute_time();
+ uint64_t nsecs = cpu_time * (info.numer / info.denom);
+ t.tv_sec = nsecs * 1e-9;
+ t.tv_usec = nsecs * 1e-3 - (t.tv_sec * 1e6);
+ return;
+ }
+#elif !defined(QT_NO_CLOCK_MONOTONIC) && !defined(QT_BOOTSTRAPPED)
if (useMonotonicTimers) {
timespec ts;
clock_gettime(CLOCK_MONOTONIC, &ts);