diff --git a/include/crucible/time.h b/include/crucible/time.h index c788869..7261013 100644 --- a/include/crucible/time.h +++ b/include/crucible/time.h @@ -81,6 +81,9 @@ namespace crucible { // Write count void update(uint64_t new_count); + // Ignore counts that go backwards + void update_monotonic(uint64_t new_count); + // Read count uint64_t count() const; diff --git a/lib/time.cc b/lib/time.cc index e7b4721..77a99ad 100644 --- a/lib/time.cc +++ b/lib/time.cc @@ -188,6 +188,17 @@ namespace crucible { return update_unlocked(new_count); } + void + RateEstimator::update_monotonic(uint64_t new_count) + { + unique_lock lock(m_mutex); + if (m_last_count == numeric_limits::max() || new_count > m_last_count) { + return update_unlocked(new_count); + } else { + return update_unlocked(m_last_count); + } + } + uint64_t RateEstimator::count() const {