opt: Ensure that the client remains in the linked list until it is destroyed

This commit is contained in:
DreamMaoMao 2026-06-29 09:58:13 +08:00
parent 634ca7a51c
commit 22ecd84225
6 changed files with 54 additions and 41 deletions

View file

@ -205,4 +205,30 @@ void wl_list_swap(struct wl_list *l1, struct wl_list *l2) {
tmp2_prev->next = l1;
tmp2_next->prev = l1;
}
}
void wl_list_safe_reinsert_prev(struct wl_list *l1, struct wl_list *l2) {
if (!l1 || !l2)
return;
if (l1 == l2)
return;
if (l1->prev == l2)
return;
wl_list_remove(l2);
wl_list_init(l2);
wl_list_insert(l1->prev, l2);
}
void wl_list_safe_reinsert_next(struct wl_list *l1, struct wl_list *l2) {
if (!l1 || !l2)
return;
if (l1 == l2)
return;
if (l1->next == l2)
return;
wl_list_remove(l2);
wl_list_init(l2);
wl_list_insert(l1, l2);
}

View file

@ -12,4 +12,6 @@ char *join_strings(char *arr[], const char *sep);
char *join_strings_with_suffix(char *arr[], const char *suffix,
const char *sep);
char *string_printf(const char *fmt, ...);
void wl_list_swap(struct wl_list *l1, struct wl_list *l2);
void wl_list_swap(struct wl_list *l1, struct wl_list *l2);
void wl_list_safe_reinsert_prev(struct wl_list *l1, struct wl_list *l2);
void wl_list_safe_reinsert_next(struct wl_list *l1, struct wl_list *l2);