Skip to content

Commit 59e3dda

Browse files
authored
wayland: fix pump events's loop drop deadlock
1 parent c846f67 commit 59e3dda

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

src/changelog/unreleased.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,3 +247,4 @@ changelog entry.
247247
- On macOS, fixed the scancode conversion for `IntlBackslash`.
248248
- On macOS, fixed redundant `SurfaceResized` event at window creation.
249249
- On Windows, fixed crash in should_apps_use_dark_mode() for Windows versions < 17763.
250+
- On Wayland, fixed `pump_events` driven loop deadlocking when loop was not drained before exit.

src/platform_impl/linux/wayland/event_loop/mod.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -739,7 +739,7 @@ impl Drop for PumpEventNotifier {
739739
if let Some(worker_waker) = self.worker_waker.as_ref() {
740740
let _ = rustix::io::write(worker_waker.as_fd(), &[0u8]);
741741
}
742-
*self.control.0.lock().unwrap() = PumpEventNotifierAction::Monitor;
742+
*self.control.0.lock().unwrap() = PumpEventNotifierAction::Shutdown;
743743
self.control.1.notify_one();
744744

745745
if let Some(handle) = self.handle.take() {
@@ -767,6 +767,14 @@ impl PumpEventNotifier {
767767
while *wait == PumpEventNotifierAction::Pause {
768768
wait = cvar.wait(wait).unwrap();
769769
}
770+
771+
// Exit the loop when we're asked to. Given that we poll
772+
// only once we can take the `prepare_read`, but in some cases
773+
// it could be not possible, we may block on `join`.
774+
if *wait == PumpEventNotifierAction::Shutdown {
775+
break 'outer;
776+
}
777+
770778
// Wake-up the main loop and put this one back to sleep.
771779
*wait = PumpEventNotifierAction::Pause;
772780
drop(wait);
@@ -802,4 +810,6 @@ enum PumpEventNotifierAction {
802810
Monitor,
803811
/// Pause monitoring.
804812
Pause,
813+
/// Shutdown the thread.
814+
Shutdown,
805815
}

0 commit comments

Comments
 (0)