From 3b89abc64391853c71cd72e4c420964054a80934 Mon Sep 17 00:00:00 2001 From: Ivailo Monev Date: Wed, 7 Jun 2023 22:18:50 +0300 Subject: [PATCH] scope the monotonic clock check to QElapsedTimer::isMonotonic() Signed-off-by: Ivailo Monev --- src/core/tools/qelapsedtimer_unix.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/core/tools/qelapsedtimer_unix.cpp b/src/core/tools/qelapsedtimer_unix.cpp index 619adb536..a4ef415f2 100644 --- a/src/core/tools/qelapsedtimer_unix.cpp +++ b/src/core/tools/qelapsedtimer_unix.cpp @@ -27,20 +27,20 @@ QT_BEGIN_NAMESPACE +bool QElapsedTimer::isMonotonic() +{ #if defined(_SC_MONOTONIC_CLOCK) -static const bool monotonicClockAvailable = (sysconf(_SC_MONOTONIC_CLOCK) >= 200112L); + static const bool monotonicClockAvailable = (sysconf(_SC_MONOTONIC_CLOCK) >= 200112L); #else -static const bool monotonicClockAvailable = (_POSIX_MONOTONIC_CLOCK > 0); + static const bool monotonicClockAvailable = (_POSIX_MONOTONIC_CLOCK > 0); #endif -bool QElapsedTimer::isMonotonic() -{ return monotonicClockAvailable; } QElapsedTimer::ClockType QElapsedTimer::clockType() { - if (Q_LIKELY(monotonicClockAvailable)) { + if (Q_LIKELY(QElapsedTimer::isMonotonic())) { return QElapsedTimer::MonotonicClock; } return QElapsedTimer::SystemTime; @@ -49,7 +49,7 @@ QElapsedTimer::ClockType QElapsedTimer::clockType() static inline void do_gettime(qint64 *sec, qint64 *frac) { struct timespec ts; - if (Q_LIKELY(monotonicClockAvailable)) { + if (Q_LIKELY(QElapsedTimer::isMonotonic())) { ::clock_gettime(CLOCK_MONOTONIC, &ts); } else { ::clock_gettime(CLOCK_REALTIME, &ts); -- 2.11.0