summaryrefslogtreecommitdiff
path: root/src/managers/eventLoop
diff options
context:
space:
mode:
authorVaxry <vaxry@vaxry.net>2024-06-25 16:05:39 +0200
committerVaxry <vaxry@vaxry.net>2024-06-25 16:05:47 +0200
commit1d70962892a6e3e1cacd3663b390bbdf81426984 (patch)
tree168f9049a02e8ecf704fa49f214810b95575240a /src/managers/eventLoop
parent918d8340afd652b011b937d29d5eea0be08467f5 (diff)
core: move to steady_clock where applicable
avoid issues when system clock gets desynchronized or changed
Diffstat (limited to 'src/managers/eventLoop')
-rw-r--r--src/managers/eventLoop/EventLoopTimer.cpp12
-rw-r--r--src/managers/eventLoop/EventLoopTimer.hpp6
2 files changed, 9 insertions, 9 deletions
diff --git a/src/managers/eventLoop/EventLoopTimer.cpp b/src/managers/eventLoop/EventLoopTimer.cpp
index dbb405e5..d3cfdf8d 100644
--- a/src/managers/eventLoop/EventLoopTimer.cpp
+++ b/src/managers/eventLoop/EventLoopTimer.cpp
@@ -2,23 +2,23 @@
#include <limits>
#include "EventLoopManager.hpp"
-CEventLoopTimer::CEventLoopTimer(std::optional<std::chrono::system_clock::duration> timeout, std::function<void(SP<CEventLoopTimer> self, void* data)> cb_, void* data_) :
+CEventLoopTimer::CEventLoopTimer(std::optional<std::chrono::steady_clock::duration> timeout, std::function<void(SP<CEventLoopTimer> self, void* data)> cb_, void* data_) :
cb(cb_), data(data_) {
if (!timeout.has_value())
expires.reset();
else
- expires = std::chrono::system_clock::now() + *timeout;
+ expires = std::chrono::steady_clock::now() + *timeout;
}
-void CEventLoopTimer::updateTimeout(std::optional<std::chrono::system_clock::duration> timeout) {
+void CEventLoopTimer::updateTimeout(std::optional<std::chrono::steady_clock::duration> timeout) {
if (!timeout.has_value()) {
expires.reset();
g_pEventLoopManager->nudgeTimers();
return;
}
- expires = std::chrono::system_clock::now() + *timeout;
+ expires = std::chrono::steady_clock::now() + *timeout;
g_pEventLoopManager->nudgeTimers();
}
@@ -26,7 +26,7 @@ void CEventLoopTimer::updateTimeout(std::optional<std::chrono::system_clock::dur
bool CEventLoopTimer::passed() {
if (!expires.has_value())
return false;
- return std::chrono::system_clock::now() > *expires;
+ return std::chrono::steady_clock::now() > *expires;
}
void CEventLoopTimer::cancel() {
@@ -47,5 +47,5 @@ float CEventLoopTimer::leftUs() {
if (!expires.has_value())
return std::numeric_limits<float>::max();
- return std::chrono::duration_cast<std::chrono::microseconds>(*expires - std::chrono::system_clock::now()).count();
+ return std::chrono::duration_cast<std::chrono::microseconds>(*expires - std::chrono::steady_clock::now()).count();
}
diff --git a/src/managers/eventLoop/EventLoopTimer.hpp b/src/managers/eventLoop/EventLoopTimer.hpp
index 73f5dc73..ad7d3986 100644
--- a/src/managers/eventLoop/EventLoopTimer.hpp
+++ b/src/managers/eventLoop/EventLoopTimer.hpp
@@ -8,11 +8,11 @@
class CEventLoopTimer {
public:
- CEventLoopTimer(std::optional<std::chrono::system_clock::duration> timeout, std::function<void(SP<CEventLoopTimer> self, void* data)> cb_, void* data_);
+ CEventLoopTimer(std::optional<std::chrono::steady_clock::duration> timeout, std::function<void(SP<CEventLoopTimer> self, void* data)> cb_, void* data_);
// if not specified, disarms.
// if specified, arms.
- void updateTimeout(std::optional<std::chrono::system_clock::duration> timeout);
+ void updateTimeout(std::optional<std::chrono::steady_clock::duration> timeout);
void cancel();
bool passed();
@@ -26,6 +26,6 @@ class CEventLoopTimer {
private:
std::function<void(SP<CEventLoopTimer> self, void* data)> cb;
void* data = nullptr;
- std::optional<std::chrono::system_clock::time_point> expires;
+ std::optional<std::chrono::steady_clock::time_point> expires;
bool wasCancelled = false;
};