Generic mutation scheduling system
IO adapted to use it Also, Atoms can now dispatch type-erased requests
This commit is contained in:
32
src/systems/scheduler/canceller.rs
Normal file
32
src/systems/scheduler/canceller.rs
Normal file
@@ -0,0 +1,32 @@
|
||||
use std::sync::atomic::{AtomicBool, Ordering};
|
||||
use std::sync::Arc;
|
||||
|
||||
use crate::atomic_inert;
|
||||
|
||||
/// A single-fire thread-safe boolean flag with relaxed ordering
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct Canceller(Arc<AtomicBool>);
|
||||
atomic_inert!(Canceller, typestr = "a canceller");
|
||||
|
||||
impl Canceller {
|
||||
/// Create a new canceller
|
||||
pub fn new() -> Self {
|
||||
Canceller(Arc::new(AtomicBool::new(false)))
|
||||
}
|
||||
|
||||
/// Check whether the operation has been cancelled
|
||||
pub fn is_cancelled(&self) -> bool {
|
||||
self.0.load(Ordering::Relaxed)
|
||||
}
|
||||
|
||||
/// Cancel the operation
|
||||
pub fn cancel(&self) {
|
||||
self.0.store(true, Ordering::Relaxed)
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for Canceller {
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user