mirror of
https://gitlab.freedesktop.org/wlroots/wlroots.git
synced 2026-04-14 08:22:25 -04:00
wlr_signal_emit_final is conceptually similar to wl_signal_emit_mutable (i.e., our old wlr_signal_emit_safe), but instead of running all listeners that were added at the time the signal emit started, we run until the list is empty, removing entries as we go along. This ensures that newly added signals are run all the same.
18 lines
691 B
C
18 lines
691 B
C
#include "util/signal.h"
|
|
|
|
void wlr_signal_emit_final(struct wl_signal *signal, void *data) {
|
|
|
|
// We need to run all listeners one final time. To support all types of list mutations and to
|
|
// ensure that all listeners including those added during this execution is run, we run until
|
|
// the list is empty, removing listeners just before we run them. To not affect the behavior of
|
|
// the listener, we re-initialize the listener's link element.
|
|
while (signal->listener_list.next != &signal->listener_list) {
|
|
struct wl_list *pos = signal->listener_list.next;
|
|
struct wl_listener *l = wl_container_of(pos, l, link);
|
|
|
|
wl_list_remove(pos);
|
|
wl_list_init(pos);
|
|
|
|
l->notify(l, data);
|
|
}
|
|
}
|