Trait atomic_counter::AtomicCounter [−][src]
pub trait AtomicCounter: Send + Sync { type PrimitiveType; 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; }
Provides an atomic counter trait that can be shared across threads.
Associated Types
type PrimitiveType
Underlying primitive type that is being shared atomically.
Required Methods
fn inc(&self) -> Self::PrimitiveType
Atomically increments the counter by one, returning the previous value.
fn add(&self, amount: Self::PrimitiveType) -> Self::PrimitiveType
Atomically increments the counter by amount, returning the previous value.
fn get(&self) -> Self::PrimitiveType
Atomically gets the current value of the counter, without modifying the counter.
fn reset(&self) -> Self::PrimitiveType
Atomically returns the current value of the counter, while resetting to count to zero.
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.
Implementors
impl AtomicCounter for RelaxedCounter type PrimitiveType = usize;
impl AtomicCounter for ConsistentCounter type PrimitiveType = usize;