chio_bounded/gauge.rs
1use crate::sync::{Arc, AtomicUsize, Ordering};
2
3/// Live entry-count gauge for a bounded structure. Cloneable handle so a
4/// telemetry exporter can read the count without locking the structure that
5/// owns it.
6#[derive(Clone, Debug)]
7pub struct SizeGauge(Arc<AtomicUsize>);
8
9#[cfg(not(loom))]
10impl Default for SizeGauge {
11 fn default() -> Self {
12 Self::new()
13 }
14}
15
16impl SizeGauge {
17 pub fn new() -> Self {
18 Self(Arc::new(AtomicUsize::new(0)))
19 }
20
21 pub fn get(&self) -> usize {
22 self.0.load(Ordering::Relaxed)
23 }
24
25 pub(crate) fn set(&self, value: usize) {
26 self.0.store(value, Ordering::Relaxed);
27 }
28}