static const bool monotonicClockAvailable = (_POSIX_MONOTONIC_CLOCK > 0);
# else
# define QT_NO_CLOCK_MONOTONIC
-static const bool monotonicClockAvailable = false;
# endif
#endif
static inline qint64 fractionAdjustment()
{
- // disabled, but otherwise indicates bad usage of QElapsedTimer
- //Q_ASSERT(monotonicClockChecked);
-
+#ifndef QT_NO_CLOCK_MONOTONIC
if (Q_LIKELY(monotonicClockAvailable)) {
// the monotonic timer is measured in nanoseconds
// 1 ms = 1000000 ns
return 1000*1000ull;
- } else {
- // gettimeofday is measured in microseconds
- // 1 ms = 1000 us
- return 1000;
}
+#endif
+ // gettimeofday is measured in microseconds
+ // 1 ms = 1000 us
+ return 1000;
}
bool QElapsedTimer::isMonotonic()
{
+#ifndef QT_NO_CLOCK_MONOTONIC
return monotonicClockAvailable;
+#else
+ return false;
+#endif
}
QElapsedTimer::ClockType QElapsedTimer::clockType()
{
- return monotonicClockAvailable ? MonotonicClock : SystemTime;
+#ifndef QT_NO_CLOCK_MONOTONIC
+ if (Q_LIKELY(monotonicClockAvailable)) {
+ return QElapsedTimer::MonotonicClock;
+ }
+#endif
+ return QElapsedTimer::SystemTime;
}
static inline void do_gettime(qint64 *sec, qint64 *frac)
{
+#ifndef QT_NO_CLOCK_MONOTONIC
if (Q_LIKELY(monotonicClockAvailable)) {
timespec ts;
clock_gettime(CLOCK_MONOTONIC, &ts);
*frac = ts.tv_nsec;
return;
}
+#endif
// use gettimeofday
struct timeval tv;
::gettimeofday(&tv, Q_NULLPTR);
timeval tv;
tv.tv_sec = sec;
+#ifndef QT_NO_CLOCK_MONOTONIC
if (Q_LIKELY(monotonicClockAvailable))
tv.tv_usec = frac / 1000;
else
+#endif
tv.tv_usec = frac;
return tv;
do_gettime(&sec, &frac);
sec = sec - t1;
frac = frac - t2;
+#ifndef QT_NO_CLOCK_MONOTONIC
if (Q_UNLIKELY(!monotonicClockAvailable))
frac *= 1000;
+#endif
return sec * Q_INT64_C(1000000000) + frac;
}