From 731f7bfc020a69ca277921c3d17a57fdcf0d7cc1 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Wed, 11 Nov 2020 03:11:40 +0100 Subject: Replace RacyFlag with OnceCell --- crates/stdx/src/lib.rs | 30 +----------------------------- 1 file changed, 1 insertion(+), 29 deletions(-) (limited to 'crates/stdx') diff --git a/crates/stdx/src/lib.rs b/crates/stdx/src/lib.rs index 59d89f47d..374ed5910 100644 --- a/crates/stdx/src/lib.rs +++ b/crates/stdx/src/lib.rs @@ -1,8 +1,5 @@ //! Missing batteries for standard libraries. -use std::{ - sync::atomic::{AtomicUsize, Ordering}, - time::Instant, -}; +use std::time::Instant; mod macros; pub mod panic_context; @@ -150,31 +147,6 @@ where left } -pub struct RacyFlag(AtomicUsize); - -impl RacyFlag { - pub const fn new() -> RacyFlag { - RacyFlag(AtomicUsize::new(!0)) - } - - pub fn get(&self, init: impl FnMut() -> bool) -> bool { - let mut init = Some(init); - self.get_impl(&mut || init.take().map_or(false, |mut f| f())) - } - - fn get_impl(&self, init: &mut dyn FnMut() -> bool) -> bool { - match self.0.load(Ordering::Relaxed) { - 0 => false, - 1 => true, - _ => { - let res = init(); - self.0.store(if res { 1 } else { 0 }, Ordering::Relaxed); - res - } - } - } -} - #[cfg(test)] mod tests { use super::*; -- cgit v1.2.3