From 1d70962892a6e3e1cacd3663b390bbdf81426984 Mon Sep 17 00:00:00 2001 From: Vaxry Date: Tue, 25 Jun 2024 16:05:39 +0200 Subject: core: move to steady_clock where applicable avoid issues when system clock gets desynchronized or changed --- src/managers/eventLoop/EventLoopTimer.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'src/managers/eventLoop/EventLoopTimer.cpp') 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 #include "EventLoopManager.hpp" -CEventLoopTimer::CEventLoopTimer(std::optional timeout, std::function self, void* data)> cb_, void* data_) : +CEventLoopTimer::CEventLoopTimer(std::optional timeout, std::function 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 timeout) { +void CEventLoopTimer::updateTimeout(std::optional 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 *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::max(); - return std::chrono::duration_cast(*expires - std::chrono::system_clock::now()).count(); + return std::chrono::duration_cast(*expires - std::chrono::steady_clock::now()).count(); } -- cgit v1.2.3