Skip to content

Commit

Permalink
backend-server-sys: wakeup when destructors are pending
Browse files Browse the repository at this point in the history
  • Loading branch information
elinorbgr committed Apr 19, 2023
1 parent 04096e2 commit 443a61d
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
2 changes: 2 additions & 0 deletions wayland-backend/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#### Bugfixes

- In the rust server backend, don't send `delete_id` messages for server-created objects.
- In the system server backend, wakeup the event loop if there are pending destructors waiting
to be precessed.

## 0.1.1 -- 16/02/2023

Expand Down
31 changes: 31 additions & 0 deletions wayland-backend/src/sys/server_impl/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,7 @@ struct GlobalUserData<D> {
pub struct State<D: 'static> {
display: *mut wl_display,
pending_destructors: Vec<PendingDestructor<D>>,
timer_source: *mut wl_event_source,
_data: std::marker::PhantomData<fn(&mut D)>,
known_globals: Vec<InnerGlobalId>,
}
Expand Down Expand Up @@ -343,10 +344,28 @@ impl<D> InnerBackend<D> {
);
}

// Insert a timer we can use to force wakeups of the libwayland inner event loop
extern "C" fn timer_noop_cb(_: *mut c_void) -> i32 {
0
}

let timer_source = unsafe {
let evl = ffi_dispatch!(WAYLAND_SERVER_HANDLE, wl_display_get_event_loop, display);

ffi_dispatch!(
WAYLAND_SERVER_HANDLE,
wl_event_loop_add_timer,
evl,
timer_noop_cb,
std::ptr::null_mut()
)
};

Ok(Self {
state: Arc::new(Mutex::new(State {
display,
pending_destructors: Vec::new(),
timer_source,
_data: std::marker::PhantomData,
known_globals: Vec::new(),
})),
Expand All @@ -369,6 +388,18 @@ impl<D> InnerBackend<D> {
},
);
}
if !state.pending_destructors.is_empty() {
// Arm the timer to trigger a wakeup of the inner event loop in 1ms, so that the user
// is indicated to call dispatch_clients() and have the destructors run
unsafe {
ffi_dispatch!(
WAYLAND_SERVER_HANDLE,
wl_event_source_timer_update,
state.timer_source,
1
)
};
}
Ok(())
}

Expand Down

0 comments on commit 443a61d

Please sign in to comment.