yui_core/util/
sync.rs

1use std::sync::Mutex;
2
3pub struct SyncCounter { 
4    count: Mutex<usize>
5}
6
7impl SyncCounter { 
8    pub fn new() -> Self { 
9        let count = Mutex::new(0);
10        Self { count }
11    }
12
13    pub fn incr(&self) -> usize { 
14        let mut c = self.count.lock().unwrap();
15        *c += 1;
16        *c
17    }
18
19    pub fn count(&self) -> usize { 
20        *self.count.lock().unwrap()
21    }
22}