Skip to content

Commit

Permalink
kms/surface: Fix racy output disable
Browse files Browse the repository at this point in the history
  • Loading branch information
Drakulix committed Dec 12, 2024
1 parent 5b89ad2 commit 9b41275
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/backend/kms/surface/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ impl Default for QueueState {

#[derive(Debug)]
pub enum ThreadCommand {
Suspend,
Suspend(SyncSender<()>),
Resume {
surface: DrmSurface,
gbm: GbmDevice<DrmDeviceFd>,
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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();

Expand All @@ -660,6 +662,8 @@ impl SurfaceThreadState {
self.loop_handle.remove(queued_render);
}
};

let _ = tx.send(());
}

fn resume(
Expand Down

0 comments on commit 9b41275

Please sign in to comment.