Codebase list wlroots / 346e524
Remove wlr_signal_emit_safe Alexander Orzechowski 1 year, 9 months ago
3 changed file(s) with 0 addition(s) and 43 deletion(s). Raw diff Collapse all Expand all
+0
-8
include/util/signal.h less more
0 #ifndef UTIL_SIGNAL_H
1 #define UTIL_SIGNAL_H
2
3 #include <wayland-server-core.h>
4
5 void wlr_signal_emit_safe(struct wl_signal *signal, void *data);
6
7 #endif
55 'log.c',
66 'region.c',
77 'shm.c',
8 'signal.c',
98 'time.c',
109 'token.c',
1110 )
+0
-34
util/signal.c less more
0 #include "util/signal.h"
1
2 static void handle_noop(struct wl_listener *listener, void *data) {
3 // Do nothing
4 }
5
6 void wlr_signal_emit_safe(struct wl_signal *signal, void *data) {
7 struct wl_listener cursor;
8 struct wl_listener end;
9
10 /* Add two special markers: one cursor and one end marker. This way, we know
11 * that we've already called listeners on the left of the cursor and that we
12 * don't want to call listeners on the right of the end marker. The 'it'
13 * function can remove any element it wants from the list without troubles.
14 * wl_list_for_each_safe tries to be safe but it fails: it works fine
15 * if the current item is removed, but not if the next one is. */
16 wl_list_insert(&signal->listener_list, &cursor.link);
17 cursor.notify = handle_noop;
18 wl_list_insert(signal->listener_list.prev, &end.link);
19 end.notify = handle_noop;
20
21 while (cursor.link.next != &end.link) {
22 struct wl_list *pos = cursor.link.next;
23 struct wl_listener *l = wl_container_of(pos, l, link);
24
25 wl_list_remove(&cursor.link);
26 wl_list_insert(pos, &cursor.link);
27
28 l->notify(l, data);
29 }
30
31 wl_list_remove(&cursor.link);
32 wl_list_remove(&end.link);
33 }