Skip to content

Commit 726422f

Browse files
committed
Avoid noexcept error when using time_point with atomic
1 parent b59a571 commit 726422f

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

core/include/prometheus/gauge.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,8 @@ class PROMETHEUS_CPP_CORE_EXPORT Gauge {
7575
private:
7676
void Change(double);
7777
std::atomic<double> value_{0.0};
78-
std::atomic<std::chrono::system_clock::time_point> time_{
79-
std::chrono::system_clock::now()};
78+
std::atomic<std::chrono::system_clock::duration> time_{
79+
std::chrono::system_clock::now().time_since_epoch()};
8080
};
8181

8282
/// \brief Return a builder to configure and register a Gauge metric.

core/src/gauge.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ void Gauge::Decrement(const double value) { Change(-1.0 * value); }
1616

1717
void Gauge::Set(const double value) {
1818
value_.store(value);
19-
time_.store(std::chrono::system_clock::now());
19+
time_.store(std::chrono::system_clock::now().time_since_epoch());
2020
}
2121

2222
void Gauge::Change(const double value) {
@@ -25,7 +25,7 @@ void Gauge::Change(const double value) {
2525
while (!value_.compare_exchange_weak(current, current + value)) {
2626
// intentionally empty block
2727
}
28-
time_.store(std::chrono::system_clock::now());
28+
time_.store(std::chrono::system_clock::now().time_since_epoch());
2929
}
3030

3131
void Gauge::SetToCurrentTime() {
@@ -43,8 +43,8 @@ ClientMetric Gauge::Collect() const {
4343

4444
bool Gauge::Expired(const std::chrono::system_clock::time_point& time,
4545
const std::chrono::seconds& ttl) const {
46-
return std::chrono::duration_cast<std::chrono::seconds>(time -
47-
time_.load()) >= ttl;
46+
return std::chrono::duration_cast<std::chrono::seconds>(
47+
time.time_since_epoch() - time_.load()) >= ttl;
4848
}
4949

5050
} // namespace prometheus

0 commit comments

Comments
 (0)