macOS RAII trace guards (#2150)

* Add TraceGuard to make tracing simpler

* Add SharedStateMutexGuard to make tracing simpler

* Add trace_scope macro

* Add missing let binding in trace_scope!
This commit is contained in:
Mads Marquart 2022-01-23 21:35:26 +01:00 committed by GitHub
parent 51bb6b751e
commit 9229e2d88b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 176 additions and 135 deletions

View file

@ -14,7 +14,11 @@ use objc::runtime::{BOOL, NO};
use crate::{
dpi::LogicalSize,
platform_impl::platform::{ffi, util::IdRef, window::SharedState},
platform_impl::platform::{
ffi,
util::IdRef,
window::{SharedState, SharedStateMutexGuard},
},
};
// Unsafe wrapper type that allows us to dispatch things that aren't Send.
@ -111,10 +115,11 @@ pub unsafe fn toggle_full_screen_async(
if !curr_mask.contains(required) {
set_style_mask(*ns_window, *ns_view, required);
if let Some(shared_state) = shared_state.upgrade() {
trace!("Locked shared state in `toggle_full_screen_callback`");
let mut shared_state_lock = shared_state.lock().unwrap();
let mut shared_state_lock = SharedStateMutexGuard::new(
shared_state.lock().unwrap(),
"toggle_full_screen_callback",
);
(*shared_state_lock).saved_style = Some(curr_mask);
trace!("Unlocked shared state in `toggle_full_screen_callback`");
}
}
}
@ -144,8 +149,8 @@ pub unsafe fn set_maximized_async(
let shared_state = MainThreadSafe(shared_state);
Queue::main().exec_async(move || {
if let Some(shared_state) = shared_state.upgrade() {
trace!("Locked shared state in `set_maximized`");
let mut shared_state_lock = shared_state.lock().unwrap();
let mut shared_state_lock =
SharedStateMutexGuard::new(shared_state.lock().unwrap(), "set_maximized");
// Save the standard frame sized if it is not zoomed
if !is_zoomed {
@ -171,8 +176,6 @@ pub unsafe fn set_maximized_async(
};
ns_window.setFrame_display_(new_rect, NO);
}
trace!("Unlocked shared state in `set_maximized`");
}
});
}