From d13646952d68f1e9daec3e528fd3a70aac76d540 Mon Sep 17 00:00:00 2001 From: Simon Rozman Date: Tue, 14 Jan 2025 12:13:00 +0100 Subject: [PATCH] progress: unify clock usage Signed-off-by: Simon Rozman --- include/stdex/progress.hpp | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/include/stdex/progress.hpp b/include/stdex/progress.hpp index 24c0c87fa..33ca9c618 100644 --- a/include/stdex/progress.hpp +++ b/include/stdex/progress.hpp @@ -81,6 +81,9 @@ namespace stdex template class lazy_progress : public progress { + public: + using clock = std::chrono::high_resolution_clock; + public: /// /// Constructs a lazy progress indicator @@ -91,7 +94,7 @@ namespace stdex m_timeout(timeout), m_start(0), m_end(0), - m_value(-1) + m_value(static_cast(-1)) {} /// @@ -114,11 +117,11 @@ namespace stdex virtual void set(_In_ T value) { if (value == m_start || value == m_end) - m_last = std::chrono::high_resolution_clock::now(); + m_last = clock::now(); else if (value == m_value) return; else { - auto now = std::chrono::high_resolution_clock::now(); + auto now = clock::now(); if (now - m_last < m_timeout) return; m_last = now; @@ -135,7 +138,7 @@ namespace stdex protected: std::chrono::nanoseconds m_timeout; - std::chrono::system_clock::time_point m_last; + clock::time_point m_last; T m_start, m_end, m_value; }; @@ -147,6 +150,9 @@ namespace stdex template class timeout_progress : public progress { + public: + using clock = std::chrono::high_resolution_clock; + public: /// /// Constructs a timeout progress indicator @@ -155,7 +161,7 @@ namespace stdex /// timeout_progress(_In_ const std::chrono::nanoseconds& timeout = std::chrono::seconds(60), _In_opt_ progress* host = nullptr) : m_host(host), - m_deadline(std::chrono::high_resolution_clock::now() + timeout) + m_deadline(clock::now() + timeout) {} /// @@ -210,12 +216,12 @@ namespace stdex { return (m_host && m_host->cancel()) || - m_deadline < std::chrono::high_resolution_clock::now(); + m_deadline < clock::now(); } protected: progress* m_host; - std::chrono::high_resolution_clock::time_point m_deadline; + clock::time_point m_deadline; }; ///