muda/src/counter.rs
Amr Bashir 6b98160e49
feat: accelerators (#6)
* feat: accelerators

* add accelerators on windows
2022-06-07 13:05:20 +02:00

23 lines
450 B
Rust

#![allow(unused)]
use std::sync::atomic::{AtomicU64, Ordering};
pub struct Counter(AtomicU64);
impl Counter {
pub const fn new() -> Self {
Self(AtomicU64::new(1))
}
pub const fn new_with_start(start: u64) -> Self {
Self(AtomicU64::new(start))
}
pub fn next(&self) -> u64 {
self.0.fetch_add(1, Ordering::Relaxed)
}
pub fn current(&self) -> u64 {
self.0.load(Ordering::Relaxed)
}
}