Skip to content

Commit

Permalink
docs(core): Document atomic increment
Browse files Browse the repository at this point in the history
Issue: #293
Issue: #526
Issue: #531
  • Loading branch information
gjasny committed Nov 12, 2021
1 parent ddf7083 commit 5b3dc67
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions core/src/gauge.cc
Expand Up @@ -17,9 +17,11 @@ void Gauge::Decrement(const double value) { Change(-1.0 * value); }
void Gauge::Set(const double value) { value_.store(value); }

void Gauge::Change(const double value) {
// C++ 20 will add std::atomic::fetch_add support for floating point types
auto current = value_.load();
while (!value_.compare_exchange_weak(current, current + value))
;
while (!value_.compare_exchange_weak(current, current + value)) {
// intentionally empty block
}
}

void Gauge::SetToCurrentTime() {
Expand Down

0 comments on commit 5b3dc67

Please sign in to comment.