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>
This commit is contained in:
parent
6451c4baeb
commit
82c2118cba
@ -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)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user