hardware 0.0.9

A no_std bare-metal hardware abstraction layer — all port I/O, memory and swap allocations are guarded at runtime. Do not consider this dependency stable before x.1.x
Documentation
use core::sync::atomic::{AtomicU32, Ordering};

pub struct Guard {
    max_ops: u32,
    counter: AtomicU32,
}

impl Guard {
    pub const fn new(max_ops: u32) -> Self {
        Self {
            max_ops,
            counter: AtomicU32::new(0),
        }
    }
    pub fn allow(&self) -> bool {
        let prev = self.counter.fetch_add(1, Ordering::AcqRel);
        prev < self.max_ops
    }
}