From 4e7990b1578e5223957dee335fcc2ad1103e076d Mon Sep 17 00:00:00 2001 From: Thom Chiovoloni Date: Thu, 3 Dec 2020 05:05:03 -0800 Subject: [PATCH] Relax orderings in window_draw_list (and make it actually atomic) --- src/window_draw_list.rs | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/window_draw_list.rs b/src/window_draw_list.rs index c9f99c1..b2f63f9 100644 --- a/src/window_draw_list.rs +++ b/src/window_draw_list.rs @@ -66,16 +66,23 @@ static WINDOW_DRAW_LIST_LOADED: std::sync::atomic::AtomicBool = impl<'ui> Drop for WindowDrawList<'ui> { fn drop(&mut self) { - WINDOW_DRAW_LIST_LOADED.store(false, std::sync::atomic::Ordering::SeqCst); + WINDOW_DRAW_LIST_LOADED.store(false, std::sync::atomic::Ordering::Release); } } impl<'ui> WindowDrawList<'ui> { pub(crate) fn new(_: &Ui<'ui>) -> Self { - if WINDOW_DRAW_LIST_LOADED.load(std::sync::atomic::Ordering::SeqCst) { + let already_loaded = WINDOW_DRAW_LIST_LOADED + .compare_exchange( + false, + true, + std::sync::atomic::Ordering::Acquire, + std::sync::atomic::Ordering::Relaxed, + ) + .is_err(); + if already_loaded { 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,