From 96c0401865e2c53a2fa350ace7238dac9bb55771 Mon Sep 17 00:00:00 2001 From: Robbert van der Helm Date: Sun, 1 Jan 2023 22:35:23 +0100 Subject: [PATCH] Replace AtomicBool with Cell https://github.com/RustAudio/baseview/pull/136#discussion_r1059198419 --- src/win/window.rs | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/win/window.rs b/src/win/window.rs index 58b924d..64dd9aa 100644 --- a/src/win/window.rs +++ b/src/win/window.rs @@ -23,7 +23,6 @@ use std::marker::PhantomData; use std::os::windows::ffi::OsStrExt; use std::ptr::null_mut; use std::rc::Rc; -use std::sync::atomic::{AtomicBool, Ordering}; use raw_window_handle::{HasRawWindowHandle, RawWindowHandle, Win32Handle}; @@ -62,7 +61,7 @@ const WIN_FRAME_TIMER: usize = 4242; pub struct WindowHandle { hwnd: Option, - is_open: Rc, + is_open: Rc>, // Ensure handle is !Send _phantom: PhantomData<*mut ()>, @@ -78,7 +77,7 @@ impl WindowHandle { } pub fn is_open(&self) -> bool { - self.is_open.load(Ordering::Relaxed) + self.is_open.get() } } @@ -96,12 +95,12 @@ unsafe impl HasRawWindowHandle for WindowHandle { } struct ParentHandle { - is_open: Rc, + is_open: Rc>, } impl ParentHandle { pub fn new(hwnd: HWND) -> (Self, WindowHandle) { - let is_open = Rc::new(AtomicBool::new(true)); + let is_open = Rc::new(Cell::new(true)); let handle = WindowHandle { hwnd: Some(hwnd), @@ -115,7 +114,7 @@ impl ParentHandle { impl Drop for ParentHandle { fn drop(&mut self) { - self.is_open.store(false, Ordering::Relaxed); + self.is_open.set(false); } }