use std::sync::{
Arc,
atomic::{AtomicBool, Ordering},
};
#[derive(Clone)]
pub struct InterruptHandler {
flag: Arc<AtomicBool>,
}
impl InterruptHandler {
pub fn new() -> Self {
Self {
flag: Arc::new(AtomicBool::new(false)),
}
}
pub fn trigger(&self) {
self.flag.store(true, Ordering::SeqCst);
}
pub fn check_and_reset(&self) -> bool {
self.flag.swap(false, Ordering::SeqCst)
}
}
impl Default for InterruptHandler {
fn default() -> Self {
Self::new()
}
}