summaryrefslogtreecommitdiffstats
path: root/src/corelib/kernel/qelapsedtimer.h
diff options
context:
space:
mode:
authorThiago Macieira <thiago.macieira@intel.com>2023-02-22 13:08:05 -0800
committerThiago Macieira <thiago.macieira@intel.com>2023-04-18 19:23:42 -0300
commitc9f4c0d45e85c7cd7c6f7c18c3f3391857135ce2 (patch)
treee2db487af8d8219df888c4d70548f0d49e214048 /src/corelib/kernel/qelapsedtimer.h
parent13f0ee021e4f60248cc7914054a2f73fcc91a983 (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.h')
-rw-r--r--src/corelib/kernel/qelapsedtimer.h9
1 files changed, 8 insertions, 1 deletions
diff --git a/src/corelib/kernel/qelapsedtimer.h b/src/corelib/kernel/qelapsedtimer.h
index ab32265cba..7d8b889f61 100644
--- a/src/corelib/kernel/qelapsedtimer.h
+++ b/src/corelib/kernel/qelapsedtimer.h
@@ -6,8 +6,9 @@
#include <QtCore/qglobal.h>
-QT_BEGIN_NAMESPACE
+#include <chrono>
+QT_BEGIN_NAMESPACE
class Q_CORE_EXPORT QElapsedTimer
{
@@ -21,6 +22,10 @@ public:
PerformanceCounter
};
+ // similar to std::chrono::*_clock
+ using Duration = std::chrono::nanoseconds;
+ using TimePoint = std::chrono::time_point<std::chrono::steady_clock, Duration>;
+
constexpr QElapsedTimer() = default;
static ClockType clockType() noexcept;
@@ -31,11 +36,13 @@ public:
void invalidate() noexcept;
bool isValid() const noexcept;
+ Duration durationElapsed() const noexcept;
qint64 nsecsElapsed() const noexcept;
qint64 elapsed() const noexcept;
bool hasExpired(qint64 timeout) const noexcept;
qint64 msecsSinceReference() const noexcept;
+ Duration durationTo(const QElapsedTimer &other) const noexcept;
qint64 msecsTo(const QElapsedTimer &other) const noexcept;
qint64 secsTo(const QElapsedTimer &other) const noexcept;