progress: unify clock usage
Signed-off-by: Simon Rozman <simon@rozman.si>
This commit is contained in:
parent
32d656ceed
commit
d13646952d
@ -81,6 +81,9 @@ namespace stdex
|
|||||||
template <class T>
|
template <class T>
|
||||||
class lazy_progress : public progress<T>
|
class lazy_progress : public progress<T>
|
||||||
{
|
{
|
||||||
|
public:
|
||||||
|
using clock = std::chrono::high_resolution_clock;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
///
|
///
|
||||||
/// Constructs a lazy progress indicator
|
/// Constructs a lazy progress indicator
|
||||||
@ -91,7 +94,7 @@ namespace stdex
|
|||||||
m_timeout(timeout),
|
m_timeout(timeout),
|
||||||
m_start(0),
|
m_start(0),
|
||||||
m_end(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)
|
virtual void set(_In_ T value)
|
||||||
{
|
{
|
||||||
if (value == m_start || value == m_end)
|
if (value == m_start || value == m_end)
|
||||||
m_last = std::chrono::high_resolution_clock::now();
|
m_last = clock::now();
|
||||||
else if (value == m_value)
|
else if (value == m_value)
|
||||||
return;
|
return;
|
||||||
else {
|
else {
|
||||||
auto now = std::chrono::high_resolution_clock::now();
|
auto now = clock::now();
|
||||||
if (now - m_last < m_timeout)
|
if (now - m_last < m_timeout)
|
||||||
return;
|
return;
|
||||||
m_last = now;
|
m_last = now;
|
||||||
@ -135,7 +138,7 @@ namespace stdex
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
std::chrono::nanoseconds m_timeout;
|
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;
|
T m_start, m_end, m_value;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -147,6 +150,9 @@ namespace stdex
|
|||||||
template <class T>
|
template <class T>
|
||||||
class timeout_progress : public progress<T>
|
class timeout_progress : public progress<T>
|
||||||
{
|
{
|
||||||
|
public:
|
||||||
|
using clock = std::chrono::high_resolution_clock;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
///
|
///
|
||||||
/// Constructs a timeout progress indicator
|
/// 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) :
|
timeout_progress(_In_ const std::chrono::nanoseconds& timeout = std::chrono::seconds(60), _In_opt_ progress<T>* host = nullptr) :
|
||||||
m_host(host),
|
m_host(host),
|
||||||
m_deadline(std::chrono::high_resolution_clock::now() + timeout)
|
m_deadline(clock::now() + timeout)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
///
|
///
|
||||||
@ -210,12 +216,12 @@ namespace stdex
|
|||||||
{
|
{
|
||||||
return
|
return
|
||||||
(m_host && m_host->cancel()) ||
|
(m_host && m_host->cancel()) ||
|
||||||
m_deadline < std::chrono::high_resolution_clock::now();
|
m_deadline < clock::now();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
progress<T>* m_host;
|
progress<T>* m_host;
|
||||||
std::chrono::high_resolution_clock::time_point m_deadline;
|
clock::time_point m_deadline;
|
||||||
};
|
};
|
||||||
|
|
||||||
///
|
///
|
||||||
|
Loading…
x
Reference in New Issue
Block a user