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>>,
}
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,