From ecec571c721fa6f49823139f0211583a797cf972 Mon Sep 17 00:00:00 2001 From: Leith Bade Date: Wed, 13 Apr 2022 10:39:12 +1000 Subject: [PATCH] Avoid noexcept error when using time_point with atomic --- core/include/prometheus/gauge.h | 4 ++-- core/src/gauge.cc | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/core/include/prometheus/gauge.h b/core/include/prometheus/gauge.h index bc6df38d..a92ebe8a 100644 --- a/core/include/prometheus/gauge.h +++ b/core/include/prometheus/gauge.h @@ -75,8 +75,8 @@ class PROMETHEUS_CPP_CORE_EXPORT Gauge { private: void Change(double); std::atomic value_{0.0}; - std::atomic time_{ - std::chrono::system_clock::now()}; + std::atomic time_{ + std::chrono::system_clock::now().time_since_epoch()}; }; /// \brief Return a builder to configure and register a Gauge metric. diff --git a/core/src/gauge.cc b/core/src/gauge.cc index e2f2aa92..9605a406 100644 --- a/core/src/gauge.cc +++ b/core/src/gauge.cc @@ -16,7 +16,7 @@ void Gauge::Decrement(const double value) { Change(-1.0 * value); } void Gauge::Set(const double value) { value_.store(value); - time_.store(std::chrono::system_clock::now()); + time_.store(std::chrono::system_clock::now().time_since_epoch()); } void Gauge::Change(const double value) { @@ -25,7 +25,7 @@ void Gauge::Change(const double value) { while (!value_.compare_exchange_weak(current, current + value)) { // intentionally empty block } - time_.store(std::chrono::system_clock::now()); + time_.store(std::chrono::system_clock::now().time_since_epoch()); } void Gauge::SetToCurrentTime() { @@ -43,8 +43,8 @@ ClientMetric Gauge::Collect() const { bool Gauge::Expired(const std::chrono::system_clock::time_point& time, const std::chrono::seconds& ttl) const { - return std::chrono::duration_cast(time - - time_.load()) >= ttl; + return std::chrono::duration_cast( + time.time_since_epoch() - time_.load()) >= ttl; } } // namespace prometheus