From 9b4127555e32060083745c381393df742c69ca60 Mon Sep 17 00:00:00 2001 From: Victoria Brekenfeld Date: Thu, 12 Dec 2024 14:13:42 +0100 Subject: [PATCH] kms/surface: Fix racy output disable --- src/backend/kms/surface/mod.rs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/backend/kms/surface/mod.rs b/src/backend/kms/surface/mod.rs index e7893dee..2fe8ef05 100644 --- a/src/backend/kms/surface/mod.rs +++ b/src/backend/kms/surface/mod.rs @@ -222,7 +222,7 @@ impl Default for QueueState { #[derive(Debug)] pub enum ThreadCommand { - Suspend, + Suspend(SyncSender<()>), Resume { surface: DrmSurface, gbm: GbmDevice, @@ -433,7 +433,9 @@ impl Surface { } pub fn suspend(&mut self) { - let _ = self.thread_command.send(ThreadCommand::Suspend); + let (tx, rx) = std::sync::mpsc::sync_channel(1); + let _ = self.thread_command.send(ThreadCommand::Suspend(tx)); + let _ = rx.recv(); } pub fn resume( @@ -553,7 +555,7 @@ fn surface_thread( event_loop .handle() .insert_source(thread_receiver, move |command, _, state| match command { - Event::Msg(ThreadCommand::Suspend) => state.suspend(), + Event::Msg(ThreadCommand::Suspend(tx)) => state.suspend(tx), Event::Msg(ThreadCommand::Resume { surface, gbm, @@ -642,7 +644,7 @@ fn surface_thread( } impl SurfaceThreadState { - fn suspend(&mut self) { + fn suspend(&mut self, tx: SyncSender<()>) { self.active.store(false, Ordering::SeqCst); let _ = self.compositor.take(); @@ -660,6 +662,8 @@ impl SurfaceThreadState { self.loop_handle.remove(queued_render); } }; + + let _ = tx.send(()); } fn resume(