scope the monotonic clock check to QElapsedTimer::isMonotonic()

Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
Ivailo Monev 2023-06-07 22:18:50 +03:00
parent 0fa8602e7b
commit 3b89abc643

View file

@ -27,20 +27,20 @@
QT_BEGIN_NAMESPACE QT_BEGIN_NAMESPACE
#if defined(_SC_MONOTONIC_CLOCK)
static const bool monotonicClockAvailable = (sysconf(_SC_MONOTONIC_CLOCK) >= 200112L);
#else
static const bool monotonicClockAvailable = (_POSIX_MONOTONIC_CLOCK > 0);
#endif
bool QElapsedTimer::isMonotonic() bool QElapsedTimer::isMonotonic()
{ {
#if defined(_SC_MONOTONIC_CLOCK)
static const bool monotonicClockAvailable = (sysconf(_SC_MONOTONIC_CLOCK) >= 200112L);
#else
static const bool monotonicClockAvailable = (_POSIX_MONOTONIC_CLOCK > 0);
#endif
return monotonicClockAvailable; return monotonicClockAvailable;
} }
QElapsedTimer::ClockType QElapsedTimer::clockType() QElapsedTimer::ClockType QElapsedTimer::clockType()
{ {
if (Q_LIKELY(monotonicClockAvailable)) { if (Q_LIKELY(QElapsedTimer::isMonotonic())) {
return QElapsedTimer::MonotonicClock; return QElapsedTimer::MonotonicClock;
} }
return QElapsedTimer::SystemTime; return QElapsedTimer::SystemTime;
@ -49,7 +49,7 @@ QElapsedTimer::ClockType QElapsedTimer::clockType()
static inline void do_gettime(qint64 *sec, qint64 *frac) static inline void do_gettime(qint64 *sec, qint64 *frac)
{ {
struct timespec ts; struct timespec ts;
if (Q_LIKELY(monotonicClockAvailable)) { if (Q_LIKELY(QElapsedTimer::isMonotonic())) {
::clock_gettime(CLOCK_MONOTONIC, &ts); ::clock_gettime(CLOCK_MONOTONIC, &ts);
} else { } else {
::clock_gettime(CLOCK_REALTIME, &ts); ::clock_gettime(CLOCK_REALTIME, &ts);