Remove wlr_signal_emit_safe
Alexander Orzechowski
1 year, 9 months ago
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
|
5 | 5 |
'log.c',
|
6 | 6 |
'region.c',
|
7 | 7 |
'shm.c',
|
8 | |
'signal.c',
|
9 | 8 |
'time.c',
|
10 | 9 |
'token.c',
|
11 | 10 |
)
|
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 | |
}
|