kutil_std/sync/counter.rs
1use std::sync::atomic::*;
2
3/// Thread-safe counter.
4#[derive(Debug)]
5pub struct Counter(AtomicUsize);
6
7impl Counter {
8 /// Constructor.
9 pub const fn new() -> Self {
10 Self(AtomicUsize::new(0))
11 }
12
13 /// Next value.
14 pub fn next(&self) -> usize {
15 self.0.fetch_add(1, Ordering::SeqCst)
16 }
17}