diff options
author | Thiago Macieira <thiago.macieira@intel.com> | 2023-02-22 13:08:05 -0800 |
---|---|---|
committer | Thiago Macieira <thiago.macieira@intel.com> | 2023-04-18 19:23:42 -0300 |
commit | c9f4c0d45e85c7cd7c6f7c18c3f3391857135ce2 (patch) | |
tree | e2db487af8d8219df888c4d70548f0d49e214048 /src/corelib/kernel/qelapsedtimer_win.cpp | |
parent | 13f0ee021e4f60248cc7914054a2f73fcc91a983 (diff) |
QElapsedTimer: rewrite using std::chrono::steady_clock everywhere
This commit deletes the direct, low-level functionality that
QElapsedTimer has carried since it was introduced. Everything now uses
only std::chrono::steady_clock and std::chrono::nanoseconds.
QDeadlineTimer temporarily still uses qt_gettime(), which is moved to
qcore_unix.cpp.
Task-number: QTBUG-110059
Change-Id: Ieec322d73c1e40ad95c8fffd174641a469b1eee5
Reviewed-by: Ahmad Samir <a.samirh78@gmail.com>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib/kernel/qelapsedtimer_win.cpp')
-rw-r--r-- | src/corelib/kernel/qelapsedtimer_win.cpp | 123 |
1 files changed, 0 insertions, 123 deletions
diff --git a/src/corelib/kernel/qelapsedtimer_win.cpp b/src/corelib/kernel/qelapsedtimer_win.cpp deleted file mode 100644 index bbd5b220fe..0000000000 --- a/src/corelib/kernel/qelapsedtimer_win.cpp +++ /dev/null @@ -1,123 +0,0 @@ -// Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only - -#include "qelapsedtimer.h" -#include "qdeadlinetimer.h" -#include "qdeadlinetimer_p.h" -#include <qt_windows.h> - -QT_BEGIN_NAMESPACE - -// Result of QueryPerformanceFrequency -static quint64 counterFrequency = 0; - -static void resolveCounterFrequency() -{ - static bool done = false; - if (done) - return; - - // Retrieve the number of high-resolution performance counter ticks per second - LARGE_INTEGER frequency; - if (!QueryPerformanceFrequency(&frequency) || frequency.QuadPart == 0) - qFatal("QueryPerformanceFrequency failed, even though Microsoft documentation promises it wouldn't."); - counterFrequency = frequency.QuadPart; - - done = true; -} - -static inline qint64 ticksToNanoseconds(qint64 ticks) -{ - // QueryPerformanceCounter uses an arbitrary frequency - qint64 seconds = ticks / counterFrequency; - qint64 nanoSeconds = (ticks - seconds * counterFrequency) * 1000000000 / counterFrequency; - return seconds * 1000000000 + nanoSeconds; -} - - -static quint64 getTickCount() -{ - resolveCounterFrequency(); - - LARGE_INTEGER counter; - bool ok = QueryPerformanceCounter(&counter); - Q_ASSERT_X(ok, "QElapsedTimer::start()", - "QueryPerformanceCounter failed, although QueryPerformanceFrequency succeeded."); - Q_UNUSED(ok); - return counter.QuadPart; -} - -quint64 qt_msectime() -{ - return ticksToNanoseconds(getTickCount()) / 1000000; -} - -QElapsedTimer::ClockType QElapsedTimer::clockType() noexcept -{ - resolveCounterFrequency(); - - return PerformanceCounter; -} - -bool QElapsedTimer::isMonotonic() noexcept -{ - return true; -} - -void QElapsedTimer::start() noexcept -{ - t1 = getTickCount(); - t2 = 0; -} - -qint64 QElapsedTimer::restart() noexcept -{ - qint64 oldt1 = t1; - t1 = getTickCount(); - t2 = 0; - return ticksToNanoseconds(t1 - oldt1) / 1000000; -} - -qint64 QElapsedTimer::nsecsElapsed() const noexcept -{ - qint64 elapsed = getTickCount() - t1; - return ticksToNanoseconds(elapsed); -} - -qint64 QElapsedTimer::elapsed() const noexcept -{ - qint64 elapsed = getTickCount() - t1; - return ticksToNanoseconds(elapsed) / 1000000; -} - -qint64 QElapsedTimer::msecsSinceReference() const noexcept -{ - return ticksToNanoseconds(t1) / 1000000; -} - -qint64 QElapsedTimer::msecsTo(const QElapsedTimer &other) const noexcept -{ - qint64 difference = other.t1 - t1; - return ticksToNanoseconds(difference) / 1000000; -} - -qint64 QElapsedTimer::secsTo(const QElapsedTimer &other) const noexcept -{ - return msecsTo(other) / 1000; -} - -bool operator<(const QElapsedTimer &v1, const QElapsedTimer &v2) noexcept -{ - return (v1.t1 - v2.t1) < 0; -} - -QDeadlineTimer QDeadlineTimer::current(Qt::TimerType timerType) noexcept -{ - static_assert(!QDeadlineTimerNanosecondsInT2); - QDeadlineTimer result; - result.t1 = ticksToNanoseconds(getTickCount()); - result.type = timerType; - return result; -} - -QT_END_NAMESPACE |