gpui: Fix send_file_drop_event holding mutex during event callback (#50173)
`send_file_drop_event` was the only event dispatch site in window.rs that called the event callback while still holding the `MacWindowState` mutex. every other callback site in the file uses the established `take() / drop(lock) / callback()` pattern which releases the lock before invoking user code. this is a latent code quality issue: no deadlock occurs today because the current file-drop callback chain does not reenter `MacWindowState`'s mutex (`Window::mouse_position()` returns a cached field `Window::refresh()` only marks a dirty flag and `cx.activate()` uses a separate `MacPlatform` mutex). but `parking_lot::Mutex` is not entering so any future platform call added inside a filedrop handler would deadlock immediately and silently. the fix brings `send_file_drop_event` in line with the rest of the file by taking the callback out of the state dropping the lock invoking the callback then reacquiring the lock to restore the callback and update state. Release Notes: - N/A
This commit is contained in:
1 parent
a4c0cb4c26
commit
cc78b536bf
1 file changed
+11
-10
@@ -2551,19 +2551,20 @@ fn send_file_drop_event(
|
||||
window_state: Arc<Mutex<MacWindowState>>,
|
||||
file_drop_event: FileDropEvent,
|
||||
) -> bool {
|
||||
let mut window_state = window_state.lock();
|
||||
let window_event_callback = window_state.event_callback.as_mut();
|
||||
if let Some(callback) = window_event_callback {
|
||||
let external_files_dragged = match file_drop_event {
|
||||
FileDropEvent::Entered { .. } => Some(true),
|
||||
FileDropEvent::Exited => Some(false),
|
||||
_ => None,
|
||||
};
|
||||
let external_files_dragged = match file_drop_event {
|
||||
FileDropEvent::Entered { .. } => Some(true),
|
||||
FileDropEvent::Exited => Some(false),
|
||||
_ => None,
|
||||
};
|
||||
|
||||
let mut lock = window_state.lock();
|
||||
if let Some(mut callback) = lock.event_callback.take() {
|
||||
drop(lock);
|
||||
callback(PlatformInput::FileDrop(file_drop_event));
|
||||
|
||||
let mut lock = window_state.lock();
|
||||
lock.event_callback = Some(callback);
|
||||
if let Some(external_files_dragged) = external_files_dragged {
|
||||
window_state.external_files_dragged = external_files_dragged;
|
||||
lock.external_files_dragged = external_files_dragged;
|
||||
}
|
||||
true
|
||||
} else {
|
||||
|
||||
Reference in new issue
Block a user