use std::sync::{Arc, Mutex};
use crate::ExponentialHistogram;
#[derive(Debug, Clone, Default)]
pub struct SharedExponentialHistogram {
inner: Arc<Mutex<ExponentialHistogram>>,
}
impl SharedExponentialHistogram {
pub fn accumulate(&self, value: f64) {
self.inner
.lock()
.expect("local mutex works")
.accumulate(value)
}
pub fn snapshot(&self) -> ExponentialHistogram {
self.inner.lock().expect("local mutex works").clone()
}
pub fn snapshot_and_reset(&self) -> ExponentialHistogram {
let mut histogram = self.inner.lock().expect("local mutex works");
let snapshot = histogram.clone();
histogram.reset();
snapshot
}
}