summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
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);