forked from Orchid/orchid
Cut down on macro nonsense
- InertAtomic replaced atomic_inert! for improved tooling support - atomic_defaults! is easier to type out than to explain in a docstring - Changed rustfmt config to better support tiny functions such as as_any
This commit is contained in:
@@ -1,32 +1,26 @@
|
||||
use std::sync::atomic::{AtomicBool, Ordering};
|
||||
use std::sync::Arc;
|
||||
|
||||
use crate::atomic_inert;
|
||||
use crate::foreign::InertAtomic;
|
||||
|
||||
/// 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 InertAtomic for Canceller {
|
||||
fn type_str() -> &'static str { "a canceller" }
|
||||
}
|
||||
|
||||
impl Canceller {
|
||||
/// Create a new canceller
|
||||
pub fn new() -> Self {
|
||||
Canceller(Arc::new(AtomicBool::new(false)))
|
||||
}
|
||||
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)
|
||||
}
|
||||
pub fn is_cancelled(&self) -> bool { self.0.load(Ordering::Relaxed) }
|
||||
|
||||
/// Cancel the operation
|
||||
pub fn cancel(&self) {
|
||||
self.0.store(true, Ordering::Relaxed)
|
||||
}
|
||||
pub fn cancel(&self) { self.0.store(true, Ordering::Relaxed) }
|
||||
}
|
||||
|
||||
impl Default for Canceller {
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
fn default() -> Self { Self::new() }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user