pub struct AtomicCounter { /* private fields */ }Expand description
A thread-safe atomic counter with increment and decrement operations.
This counter uses relaxed ordering for maximum performance while maintaining atomicity across threads.
Implementations§
Source§impl AtomicCounter
impl AtomicCounter
Sourcepub const fn new() -> AtomicCounter
pub const fn new() -> AtomicCounter
Create a new atomic counter with initial value 0.
Sourcepub const fn with_initial(initial: usize) -> AtomicCounter
pub const fn with_initial(initial: usize) -> AtomicCounter
Create a new atomic counter with the given initial value.
Sourcepub fn add(&self, amount: usize) -> usize
pub fn add(&self, amount: usize) -> usize
Increment the counter by a specific amount and return the previous value.
Sourcepub fn fetch_add(&self, amount: usize, ordering: Ordering) -> usize
pub fn fetch_add(&self, amount: usize, ordering: Ordering) -> usize
Atomic fetch-and-add operation compatible with std::sync::atomic interface. This provides a lower-level interface for compatibility.
Sourcepub fn decrement(&self) -> usize
pub fn decrement(&self) -> usize
Decrement the counter by 1 and return the previous value. Note: This will wrap around on underflow.
Sourcepub fn subtract(&self, amount: usize) -> usize
pub fn subtract(&self, amount: usize) -> usize
Decrement the counter by a specific amount and return the previous value. Note: This will wrap around on underflow.
Sourcepub fn max(&self, value: usize) -> usize
pub fn max(&self, value: usize) -> usize
Atomically set the counter to the maximum of its current value and the given value.
Trait Implementations§
Source§impl Clone for AtomicCounter
impl Clone for AtomicCounter
Source§fn clone(&self) -> AtomicCounter
fn clone(&self) -> AtomicCounter
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more