libweston: Introduce safer emission of wayland signals
Wayland signals (wl_signal) do not reliably handle changes to the notification list during signal emission. Such scenarios occasionally come up (e.g., #415 (closed)) and can be difficult to investigate and debug.
The first commit in the MR introduces the weston_signal_emit_mutable()
function (copied from wlr_signal_emit_safe from wlroots) which can be used in place of wl_signal_emit()
and which safely implements the following behavior regarding notification list changes:
-
Listeners deleted during a signal emission and which have not already been notified at the time of deletion are not notified by that emission.
-
New listeners added during emission are ignored by that emission.
-
Listeners which are deleted and then readded during emission are ignored by that emission.
-
Repurposing a listener during a signal emission without an explicit removal and re-addition is not supported.
The second commit in this MR changes the wl_surface::destroy_signal to use weston_signal_emit_safe, both as an example of using weston_signal, and as a fix for #415 (closed).
If we agree on migrating to weston_signal_emit_safe() I will update the whole codebase accordingly.