use alloc::sync::Arc;
use core::sync::atomic::{AtomicBool, Ordering};
pub struct Shutdown {
flag: Arc<AtomicBool>,
}
impl Shutdown {
pub fn new() -> Self {
Shutdown {
flag: Arc::new(AtomicBool::new(false)),
}
}
pub fn trigger(&self) {
self.flag.store(true, Ordering::Release);
}
pub fn is_shutdown(&self) -> bool {
self.flag.load(Ordering::Acquire)
}
}
impl Default for Shutdown {
fn default() -> Self {
Self::new()
}
}
impl Clone for Shutdown {
fn clone(&self) -> Self {
Shutdown {
flag: self.flag.clone(),
}
}
}