summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAlex <qt-info@nokia.com>2011-06-14 17:21:39 +1000
committerAlex <qt-info@nokia.com>2011-06-14 17:21:39 +1000
commit0852fae324f83b2a0a689b995fcacf2e9d4fc5ca (patch)
tree38972d78d12b394628532e63ab9badb202848b95 /src
parent164e4f5813d8beb30ce8e1555f49f84b785c0d51 (diff)
use MacOS specific monotonic time
Diffstat (limited to 'src')
-rw-r--r--src/plugins/sensors/dummy/dummycommon.cpp22
1 files changed, 21 insertions, 1 deletions
diff --git a/src/plugins/sensors/dummy/dummycommon.cpp b/src/plugins/sensors/dummy/dummycommon.cpp
index 643342d4..33e1512f 100644
--- a/src/plugins/sensors/dummy/dummycommon.cpp
+++ b/src/plugins/sensors/dummy/dummycommon.cpp
@@ -47,6 +47,9 @@
// the function isn't actually implemented.
#else
#include <time.h>
+#ifdef Q_OS_MAC
+#include <mach/mach_time.h>
+#endif
#endif
dummycommon::dummycommon(QSensor *sensor)
@@ -88,6 +91,18 @@ void dummycommon::timerEvent(QTimerEvent * /*event*/)
poll();
}
+#ifdef Q_OS_MAC
+//taken from qelapsedtimer_mac.cpp
+static mach_timebase_info_data_t info = {0,0};
+static qint64 absoluteToNSecs(qint64 cpuTime)
+{
+ if (info.denom == 0)
+ mach_timebase_info(&info);
+ qint64 nsecs = cpuTime * info.numer / info.denom;
+ return nsecs;
+}
+#endif
+
quint64 dummycommon::getTimestamp()
{
#ifdef Q_OS_WINCE
@@ -102,10 +117,15 @@ quint64 dummycommon::getTimestamp()
uli.HighPart = userTime.dwHighDateTime;
ULONGLONG systemTimeInMS = uli.QuadPart/10000;
return static_cast<quint64>(systemTimeInMS);
+#elif Q_OS_MAC
+ uint64_t cpu_time = mach_absolute_time();
+ uint64_t nsecs = absoluteToNSecs(cpu_time);
+
+ quint64 result = (nsecs * 0.001); //scale to microseconds
+ return result;
#else
struct timespec tv;
int ok;
-
ok = clock_gettime(CLOCK_MONOTONIC, &tv);
Q_ASSERT(ok == 0);