Skip to content

Add custom event support to loop trait

Tom Wagner requested to merge ryuukyu/pipewire-rs:channel into main

This adds bindings for pw_loop_add_event and pw_loop_signal_event so we can create custom events and hook them into the loop.

This would be the start of enabling inter-thread communication, for sendings events to a thread currently running the mainloop.

This MR is marked as Draft, because I have a few questions, and because it might be unsound right now.

  1. Why does fn add_signal_local call assert_main_thread(), and why is it only local? I'm not an expert about thread safety in pipewire, so do we have to take similar caution in the two new methods? Resolved.

  2. Both add_signal_local and add_event return a Source, and signal_event takes a source to signal the event associated with that source.
    It might be unsound to let users pass a source from add_signal_local to signal_event, but I'm not sure.
    Should we just create a LoopEvent newtype for event sources?
    Done.

Edit:

  1. We also need to be careful about users creating multiple loops, and sending the event to the wrong one. If we make a LoopEvent newtype, we should probably add a signal method to that, which signals the loop stored in the source, instead of having the signal_event trait method. This would also be more ergonomic. Thoughts? Done.
Edited by Tom Wagner

Merge request reports

Loading