use std::sync::Arc;
use std::sync::atomic::{AtomicBool, Ordering};
#[derive(Clone)]
pub(crate) struct CompileCancel {
flag: Arc<AtomicBool>,
}
impl CompileCancel {
pub(crate) fn new() -> Self {
Self {
flag: Arc::new(AtomicBool::new(false)),
}
}
pub(crate) fn cancel(&self) {
self.flag.store(true, Ordering::Release);
}
pub(crate) fn is_cancelled(&self) -> bool {
self.flag.load(Ordering::Acquire)
}
}
pub(crate) fn cancelled(cancel: Option<&CompileCancel>) -> bool {
cancel.is_some_and(CompileCancel::is_cancelled)
}
pub(crate) fn cancelled_error() -> crate::SimulatorError {
crate::SimulatorError::new(crate::SimulatorErrorKind::Codegen(
crate::CodegenError::Cancelled,
))
}