Skip to main content

conc_util/sync/
onceflag.rs

1use core::sync::atomic::{AtomicBool, Ordering};
2
3pub struct OnceFlag(AtomicBool);
4
5impl OnceFlag {
6    pub fn new() -> Self {
7        Self(AtomicBool::new(false))
8    }
9
10    pub fn fire(&self) -> bool {
11        self.0.swap(true, Ordering::AcqRel)
12    }
13
14    pub fn fired(&self) -> bool {
15        self.0.load(Ordering::Acquire)
16    }
17}