Trait AtomicCounter

Source
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§

Source

type PrimitiveType

Underlying primitive type that is being shared atomically.

Required Methods§

Source

fn inc(&self) -> Self::PrimitiveType

Atomically increments the counter by one, returning the previous value.

Source

fn add(&self, amount: Self::PrimitiveType) -> Self::PrimitiveType

Atomically increments the counter by amount, returning the previous value.

Source

fn get(&self) -> Self::PrimitiveType

Atomically gets the current value of the counter, without modifying the counter.

Source

fn reset(&self) -> Self::PrimitiveType

Atomically returns the current value of the counter, while resetting to count to zero.

Source

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§