use std::sync::atomic::{AtomicU64, Ordering};
pub const MAX_REDUCTIONS: u64 = 4000;
pub struct ReductionCounter {
count: AtomicU64,
}
impl ReductionCounter {
pub fn new() -> Self {
Self {
count: AtomicU64::new(0),
}
}
pub fn increment(&self) -> u64 {
self.count.fetch_add(1, Ordering::Relaxed)
}
pub fn reset(&self) {
self.count.store(0, Ordering::Relaxed);
}
#[allow(dead_code)]
pub fn should_preempt(&self) -> bool {
self.count.load(Ordering::Relaxed) >= MAX_REDUCTIONS
}
}
impl Default for ReductionCounter {
fn default() -> Self {
Self::new()
}
}