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 with_initial(initial: usize) -> Self
pub const fn with_initial(initial: usize) -> Self
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§impl Debug for AtomicCounter
impl Debug for AtomicCounter
Auto Trait Implementations§
impl !Freeze for AtomicCounter
impl RefUnwindSafe for AtomicCounter
impl Send for AtomicCounter
impl Sync for AtomicCounter
impl Unpin for AtomicCounter
impl UnsafeUnpin for AtomicCounter
impl UnwindSafe for AtomicCounter
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more