Skip to main content

conc_util/sync/
onceflag.rs

1use core::sync::atomic::{AtomicBool, Ordering};
2
3#[derive(Debug)]
4pub struct OnceFlag(AtomicBool);
5
6impl OnceFlag {
7    pub fn new() -> Self {
8        Self(AtomicBool::new(false))
9    }
10
11    pub fn fire(&self) -> bool {
12        self.0.swap(true, Ordering::AcqRel)
13    }
14
15    pub fn fired(&self) -> bool {
16        self.0.load(Ordering::Acquire)
17    }
18
19    pub fn fired_mut(&mut self) -> bool {
20        *self.0.get_mut()
21    }
22}