use std::sync::atomic::{AtomicU64, Ordering};
#[derive(Debug)]
pub struct GenerationCounter {
counter: AtomicU64,
}
impl GenerationCounter {
#[inline]
pub const fn new() -> Self {
Self {
counter: AtomicU64::new(0),
}
}
#[inline]
pub fn get(&self) -> u64 {
self.counter.load(Ordering::Relaxed)
}
#[inline]
pub fn increment(&self) {
self.counter.fetch_add(1, Ordering::Relaxed);
}
#[inline]
pub fn set(&self, value: u64) {
self.counter.store(value, Ordering::Relaxed);
}
}
impl Default for GenerationCounter {
fn default() -> Self {
Self::new()
}
}
impl Clone for GenerationCounter {
fn clone(&self) -> Self {
Self {
counter: AtomicU64::new(self.get()),
}
}
}