pub trait AtomicCounter: Send + Sync {
type PrimitiveType;
// Required methods
fn inc(&self) -> Self::PrimitiveType;
fn add(&self, amount: Self::PrimitiveType) -> Self::PrimitiveType;
fn get(&self) -> Self::PrimitiveType;
fn reset(&self) -> Self::PrimitiveType;
fn into_inner(self) -> Self::PrimitiveType;
}Expand description
Provides an atomic counter trait that can be shared across threads.
Required Associated Types§
Sourcetype PrimitiveType
type PrimitiveType
Underlying primitive type that is being shared atomically.
Required Methods§
Sourcefn inc(&self) -> Self::PrimitiveType
fn inc(&self) -> Self::PrimitiveType
Atomically increments the counter by one, returning the previous value.
Sourcefn add(&self, amount: Self::PrimitiveType) -> Self::PrimitiveType
fn add(&self, amount: Self::PrimitiveType) -> Self::PrimitiveType
Atomically increments the counter by amount, returning the previous value.
Sourcefn get(&self) -> Self::PrimitiveType
fn get(&self) -> Self::PrimitiveType
Atomically gets the current value of the counter, without modifying the counter.
Sourcefn reset(&self) -> Self::PrimitiveType
fn reset(&self) -> Self::PrimitiveType
Atomically returns the current value of the counter, while resetting to count to zero.
Sourcefn into_inner(self) -> Self::PrimitiveType
fn into_inner(self) -> Self::PrimitiveType
Consume the atomic counter and return the primitive type.
This is safe because passing self by value guarantees that no other threads are concurrently accessing the atomic data.