progress: unify clock usage

Signed-off-by: Simon Rozman <simon@rozman.si>
This commit is contained in:
Simon Rozman 2025-01-14 12:13:00 +01:00
parent 32d656ceed
commit d13646952d

View File

@ -81,6 +81,9 @@ namespace stdex
template <class T>
class lazy_progress : public progress<T>
{
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<T>(-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 T>
class timeout_progress : public progress<T>
{
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<T>* 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<T>* m_host;
std::chrono::high_resolution_clock::time_point m_deadline;
clock::time_point m_deadline;
};
///