Merge pull request #237 from nico-abram/patch-1

Replace static mut bool with AtomicBool
This commit is contained in:
Joonas Javanainen 2019-07-22 23:53:31 +03:00 committed by GitHub
commit 00a724283e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -62,24 +62,20 @@ pub struct WindowDrawList<'ui> {
_phantom: PhantomData<&'ui Ui<'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> { impl<'ui> Drop for WindowDrawList<'ui> {
fn drop(&mut self) { fn drop(&mut self) {
unsafe { WINDOW_DRAW_LIST_LOADED.store(false, std::sync::atomic::Ordering::SeqCst);
WINDOW_DRAW_LIST_LOADED = false;
}
} }
} }
impl<'ui> WindowDrawList<'ui> { impl<'ui> WindowDrawList<'ui> {
pub(crate) fn new(_: &Ui<'ui>) -> Self { pub(crate) fn new(_: &Ui<'ui>) -> Self {
unsafe { if WINDOW_DRAW_LIST_LOADED.load(std::sync::atomic::Ordering::SeqCst) {
if WINDOW_DRAW_LIST_LOADED { panic!("WindowDrawList is already loaded! You can only load one instance of it!")
panic!("WindowDrawList is already loaded! You can only load one instance of it!")
}
WINDOW_DRAW_LIST_LOADED = true;
} }
WINDOW_DRAW_LIST_LOADED.store(true, std::sync::atomic::Ordering::SeqCst);
Self { Self {
draw_list: unsafe { sys::igGetWindowDrawList() }, draw_list: unsafe { sys::igGetWindowDrawList() },
_phantom: PhantomData, _phantom: PhantomData,