Skip to main content

AtomicStats

Struct AtomicStats 

Source
pub struct AtomicStats { /* private fields */ }
Expand description

Atomic statistics for safe concurrent access

This structure provides lock-free atomic counters for buffer statistics. It can be safely shared between threads without mutexes.

§Memory Layout

The structure is cache-line aligned to prevent false sharing.

§Thread Safety

All operations are atomic and use relaxed ordering where appropriate.

Implementations§

Source§

impl AtomicStats

Source

pub const fn new() -> AtomicStats

Create new atomic statistics with all counters set to zero

Source

pub fn record_write(&self)

Record a successful write operation

Source

pub fn record_read(&self)

Record a successful read operation

Source

pub fn record_underflow(&self)

Record an underflow event (read when empty)

Source

pub fn record_overflow(&self)

Record an overflow event (write when full)

Source

pub fn update_peak(&self, current_fill: usize)

Update peak fill level (0-1000 representing 0.0-1.0)

§Arguments
  • current_fill - Current fill level (0-1000)

This uses a compare-exchange loop to atomically update the peak.

Source

pub fn snapshot(&self) -> BufferStats

Get a consistent snapshot of current statistics

§Returns

A BufferStats struct with a snapshot of all counters. Note that the snapshot may not be perfectly consistent due to concurrent updates, but it’s good enough for monitoring.

Source

pub fn reset(&self)

Reset all statistics to zero

Trait Implementations§

Source§

impl Debug for AtomicStats

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl Default for AtomicStats

Source§

fn default() -> AtomicStats

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> AsAny for T
where T: 'static,

Source§

fn as_any(&self) -> &(dyn Any + 'static)

Convert to &dyn std::any::Any
Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert to &mut dyn std::any::Any
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.