From 79951acf39fbb1b44e4313167926dfe8be7e20e5 Mon Sep 17 00:00:00 2001 From: Nicolas Date: Mon, 15 Jul 2019 02:56:56 -0300 Subject: [PATCH] Replace static mut bool with AtomicBool --- src/window_draw_list.rs | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/src/window_draw_list.rs b/src/window_draw_list.rs index 2a35c70..e00608e 100644 --- a/src/window_draw_list.rs +++ b/src/window_draw_list.rs @@ -62,24 +62,20 @@ pub struct WindowDrawList<'ui> { _phantom: PhantomData<&'ui Ui<'ui>>, } -static mut WINDOW_DRAW_LIST_LOADED: bool = false; +static WINDOW_DRAW_LIST_LOADED: std::sync::atomic::AtomicBool = std::sync::atomic::AtomicBool::new(false); impl<'ui> Drop for WindowDrawList<'ui> { fn drop(&mut self) { - unsafe { - WINDOW_DRAW_LIST_LOADED = false; - } + WINDOW_DRAW_LIST_LOADED.store(false, std::sync::atomic::Ordering::SeqCst); } } impl<'ui> WindowDrawList<'ui> { pub(crate) fn new(_: &Ui<'ui>) -> Self { - unsafe { - if WINDOW_DRAW_LIST_LOADED { - panic!("WindowDrawList is already loaded! You can only load one instance of it!") - } - WINDOW_DRAW_LIST_LOADED = true; + if WINDOW_DRAW_LIST_LOADED.load(std::sync::atomic::Ordering::SeqCst) { + panic!("WindowDrawList is already loaded! You can only load one instance of it!") } + WINDOW_DRAW_LIST_LOADED.store(true, std::sync::atomic::Ordering::SeqCst); Self { draw_list: unsafe { sys::igGetWindowDrawList() }, _phantom: PhantomData,