exponential_histogram/
shared.rs1use std::sync::{Arc, Mutex};
2
3use crate::ExponentialHistogram;
4
5#[derive(Debug, Clone, Default)]
7pub struct SharedExponentialHistogram {
8 inner: Arc<Mutex<ExponentialHistogram>>,
9}
10
11impl SharedExponentialHistogram {
12 pub fn accumulate(&self, value: f64) {
14 self.inner
15 .lock()
16 .expect("local mutex works")
17 .accumulate(value)
18 }
19
20 pub fn snapshot(&self) -> ExponentialHistogram {
23 self.inner.lock().expect("local mutex works").clone()
24 }
25
26 pub fn snapshot_and_reset(&self) -> ExponentialHistogram {
29 let mut histogram = self.inner.lock().expect("local mutex works");
30 let snapshot = histogram.clone();
31 histogram.reset();
32 snapshot
33 }
34}