mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-10-31 22:25:38 -04:00
hook: make safer
Also protect against removal of the next hook by using a cursor.
This commit is contained in:
parent
bdeedad1d6
commit
65e00631da
1 changed files with 12 additions and 4 deletions
|
|
@ -80,20 +80,28 @@ static inline void spa_hook_remove(struct spa_hook *hook)
|
|||
/** Call all hooks in a list, starting from the given one and optionally stopping
|
||||
* after calling the first non-NULL function, returns the number of methods
|
||||
* called */
|
||||
#define spa_hook_list_do_call(l,start,type,method,once,...) ({ \
|
||||
#define spa_hook_list_do_call(l,start,type,method,once,...) \
|
||||
({ \
|
||||
struct spa_hook_list *list = l; \
|
||||
struct spa_list *s = start ? (struct spa_list *)start : &list->list; \
|
||||
struct spa_hook *ci, *t; \
|
||||
struct spa_hook cursor = { 0, }; \
|
||||
struct spa_hook *ci; \
|
||||
int count = 0; \
|
||||
spa_list_for_each_safe_next(ci, t, &list->list, s, link) { \
|
||||
spa_list_prepend(s, &cursor.link); \
|
||||
for(ci = spa_list_first(&cursor.link, struct spa_hook, link); \
|
||||
&ci->link != s; \
|
||||
ci = spa_list_next(&cursor, link)) { \
|
||||
const type *cb = ci->funcs; \
|
||||
if (cb->method) { \
|
||||
spa_list_remove(&ci->link); \
|
||||
spa_list_append(&cursor.link, &ci->link); \
|
||||
if (cb && cb->method) { \
|
||||
cb->method(ci->data, ## __VA_ARGS__); \
|
||||
count++; \
|
||||
if (once) \
|
||||
break; \
|
||||
} \
|
||||
} \
|
||||
spa_list_remove(&cursor.link); \
|
||||
count; \
|
||||
})
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue