diff options
author | Matt Fischer <matt.fischer@garmin.com> | 2014-10-14 16:57:20 -0500 |
---|---|---|
committer | Matt Fischer <matt.fischer@garmin.com> | 2014-11-07 22:59:43 +0100 |
commit | 82c2118cba2744000cff7cd3e5e952df775f5aba (patch) | |
tree | 52ecef57a6ed24ca3f16d060eef853fb8fa75204 /src | |
parent | 6451c4baeb829708628a5759ee3d3978489acc7d (diff) |
Improve QElapsedTimer resolution on QNX
The standard POSIX clock functions are present on QNX, but only
return timing information with millisecond accuracy. To get
accuracy beyond that, platform-specific functions must be used.
Change-Id: I54a0550f1865dbea3c60a86ecd8ad99df3fe42b4
Reviewed-by: Frank Osterfeld <frank.osterfeld@kdab.com>
Reviewed-by: Bernd Weimer <bweimer@blackberry.com>
Reviewed-by: Rafael Roquetto <rafael.roquetto@kdab.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/corelib/tools/qelapsedtimer_unix.cpp | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/src/corelib/tools/qelapsedtimer_unix.cpp b/src/corelib/tools/qelapsedtimer_unix.cpp index 5b26d551a7..9dd5df0266 100644 --- a/src/corelib/tools/qelapsedtimer_unix.cpp +++ b/src/corelib/tools/qelapsedtimer_unix.cpp @@ -35,8 +35,12 @@ #define _POSIX_C_SOURCE 200809L #include "qelapsedtimer.h" -#ifdef Q_OS_VXWORKS +#if defined(Q_OS_VXWORKS) #include "qfunctions_vxworks.h" +#elif defined(Q_OS_QNX) +#include <sys/neutrino.h> +#include <sys/syspage.h> +#include <inttypes.h> #else #include <sys/time.h> #include <time.h> @@ -84,7 +88,18 @@ QT_BEGIN_NAMESPACE * see http://pubs.opengroup.org/onlinepubs/9699919799/functions/clock_getres.html */ -#ifndef CLOCK_REALTIME +#if defined(Q_OS_QNX) +static inline void qt_clock_gettime(clockid_t clock, struct timespec *ts) +{ + // The standard POSIX clock calls only have 1ms accuracy on QNX. To get + // higher accuracy, this platform-specific function must be used instead + quint64 cycles_per_sec = SYSPAGE_ENTRY(qtime)->cycles_per_sec; + quint64 cycles = ClockCycles(); + ts->tv_sec = cycles / cycles_per_sec; + quint64 mod = cycles % cycles_per_sec; + ts->tv_nsec = mod * Q_INT64_C(1000000000) / cycles_per_sec; +} +#elif !defined(CLOCK_REALTIME) # define CLOCK_REALTIME 0 static inline void qt_clock_gettime(int, struct timespec *ts) { |