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
impl AtomicStats
Sourcepub const fn new() -> AtomicStats
pub const fn new() -> AtomicStats
Create new atomic statistics with all counters set to zero
Sourcepub fn record_write(&self)
pub fn record_write(&self)
Record a successful write operation
Sourcepub fn record_read(&self)
pub fn record_read(&self)
Record a successful read operation
Sourcepub fn record_underflow(&self)
pub fn record_underflow(&self)
Record an underflow event (read when empty)
Sourcepub fn record_overflow(&self)
pub fn record_overflow(&self)
Record an overflow event (write when full)
Sourcepub fn update_peak(&self, current_fill: usize)
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.
Sourcepub fn snapshot(&self) -> BufferStats
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.