pub trait CounterFn {
// Required methods
fn increment(&self, value: u64);
fn absolute(&self, value: u64);
}
Expand description
A counter handler.
Required Methods§
sourcefn increment(&self, value: u64)
fn increment(&self, value: u64)
Increments the counter by the given amount.
Returns the previous value.
sourcefn absolute(&self, value: u64)
fn absolute(&self, value: u64)
Sets the counter to at least the given amount.
This is intended to support use cases where multiple callers are attempting to synchronize this counter with an external counter that they have no control over. As multiple callers may read that external counter, and attempt to set it here, there could be reordering issues where a caller attempts to set an older (smaller) value after the counter has been updated to the latest (larger) value.
This method must cope with those cases. An example of doing so atomically can be found in
AtomicCounter
.
Returns the previous value.