mirror of
https://github.com/Zygo/bees.git
synced 2025-05-18 05:45:45 +02:00
time: add update_monotonic to RateEstimator
update_monotonic does not reset the counter if a new count is smaller than earlier counts. Useful when consuming an unsorted stream of eveent counts. Signed-off-by: Zygo Blaxell <bees@furryterror.org>
This commit is contained in:
parent
d367c6364c
commit
2aacdcd95f
@ -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;
|
||||
|
||||
|
11
lib/time.cc
11
lib/time.cc
@ -188,6 +188,17 @@ namespace crucible {
|
||||
return update_unlocked(new_count);
|
||||
}
|
||||
|
||||
void
|
||||
RateEstimator::update_monotonic(uint64_t new_count)
|
||||
{
|
||||
unique_lock<mutex> lock(m_mutex);
|
||||
if (m_last_count == numeric_limits<uint64_t>::max() || new_count > m_last_count) {
|
||||
return update_unlocked(new_count);
|
||||
} else {
|
||||
return update_unlocked(m_last_count);
|
||||
}
|
||||
}
|
||||
|
||||
uint64_t
|
||||
RateEstimator::count() const
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user