mirror of
https://gitlab.freedesktop.org/wlroots/wlroots.git
synced 2025-12-15 08:56:26 -05:00
Add wlr_signal_emit_safe
This commit is contained in:
parent
3497e53516
commit
5e58d46cc1
43 changed files with 265 additions and 182 deletions
|
|
@ -4,6 +4,7 @@ lib_wlr_util = static_library(
|
|||
'log.c',
|
||||
'os-compatibility.c',
|
||||
'region.c',
|
||||
'signal.c',
|
||||
),
|
||||
include_directories: wlr_inc,
|
||||
dependencies: [wayland_server, pixman],
|
||||
|
|
|
|||
34
util/signal.c
Normal file
34
util/signal.c
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
#include <wlr/util/signal.h>
|
||||
|
||||
static void handle_noop(struct wl_listener *listener, void *data) {
|
||||
// Do nothing
|
||||
}
|
||||
|
||||
void wlr_signal_emit_safe(struct wl_signal *signal, void *data) {
|
||||
struct wl_listener cursor;
|
||||
struct wl_listener end;
|
||||
|
||||
/* Add two special markers: one cursor and one end marker. This way, we know
|
||||
* that we've already called listeners on the left of the cursor and that we
|
||||
* don't want to call listeners on the right of the end marker. The 'it'
|
||||
* function can remove any element it wants from the list without troubles.
|
||||
* wl_list_for_each_safe tries to be safe but it fails: it works fine
|
||||
* if the current item is removed, but not if the next one is. */
|
||||
wl_list_insert(&signal->listener_list, &cursor.link);
|
||||
cursor.notify = handle_noop;
|
||||
wl_list_insert(signal->listener_list.prev, &end.link);
|
||||
end.notify = handle_noop;
|
||||
|
||||
while (cursor.link.next != &end.link) {
|
||||
struct wl_list *pos = cursor.link.next;
|
||||
struct wl_listener *l = wl_container_of(pos, l, link);
|
||||
|
||||
wl_list_remove(&cursor.link);
|
||||
wl_list_insert(pos, &cursor.link);
|
||||
|
||||
l->notify(l, data);
|
||||
}
|
||||
|
||||
wl_list_remove(&cursor.link);
|
||||
wl_list_remove(&end.link);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue