Commit 82c2118c authored by Matt Fischer's avatar Matt Fischer
Browse files

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: default avatarFrank Osterfeld <frank.osterfeld@kdab.com>
Reviewed-by: default avatarBernd Weimer <bweimer@blackberry.com>
Reviewed-by: default avatarRafael Roquetto <rafael.roquetto@kdab.com>
Showing with 17 additions and 2 deletions
......@@ -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)
{
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment