mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-11-06 13:30:01 -05:00
list: add iteration with a cursor
Iterating a list with a cursor is heavier but is safe against removal of any element in the list. Move the hook cursor iterator to list.
This commit is contained in:
parent
813506a614
commit
2de7f9cc03
2 changed files with 19 additions and 11 deletions
|
|
@ -85,16 +85,11 @@ static inline void spa_hook_remove(struct spa_hook *hook)
|
||||||
({ \
|
({ \
|
||||||
struct spa_hook_list *list = l; \
|
struct spa_hook_list *list = l; \
|
||||||
struct spa_list *s = start ? (struct spa_list *)start : &list->list; \
|
struct spa_list *s = start ? (struct spa_list *)start : &list->list; \
|
||||||
struct spa_hook cursor = { 0, }; \
|
struct spa_hook cursor = { 0 }, *ci; \
|
||||||
struct spa_hook *ci; \
|
|
||||||
int count = 0; \
|
int count = 0; \
|
||||||
spa_list_prepend(s, &cursor.link); \
|
spa_list_cursor_start(cursor, s, link); \
|
||||||
for(ci = spa_list_first(&cursor.link, struct spa_hook, link); \
|
spa_list_for_each_cursor(ci, cursor, &list->list, link) { \
|
||||||
&ci->link != s; \
|
|
||||||
ci = spa_list_next(&cursor, link)) { \
|
|
||||||
const type *cb = ci->funcs; \
|
const type *cb = ci->funcs; \
|
||||||
spa_list_remove(&ci->link); \
|
|
||||||
spa_list_append(&cursor.link, &ci->link); \
|
|
||||||
if (cb && cb->method) { \
|
if (cb && cb->method) { \
|
||||||
cb->method(ci->data, ## __VA_ARGS__); \
|
cb->method(ci->data, ## __VA_ARGS__); \
|
||||||
count++; \
|
count++; \
|
||||||
|
|
@ -102,7 +97,7 @@ static inline void spa_hook_remove(struct spa_hook *hook)
|
||||||
break; \
|
break; \
|
||||||
} \
|
} \
|
||||||
} \
|
} \
|
||||||
spa_list_remove(&cursor.link); \
|
spa_list_cursor_end(cursor, link); \
|
||||||
count; \
|
count; \
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -84,7 +84,7 @@ static inline void spa_list_remove(struct spa_list *elem)
|
||||||
pos = spa_list_next(pos, member))
|
pos = spa_list_next(pos, member))
|
||||||
|
|
||||||
#define spa_list_for_each(pos, head, member) \
|
#define spa_list_for_each(pos, head, member) \
|
||||||
spa_list_for_each_next(pos, head, head, member) \
|
spa_list_for_each_next(pos, head, head, member)
|
||||||
|
|
||||||
#define spa_list_for_each_safe_next(pos, tmp, head, curr, member) \
|
#define spa_list_for_each_safe_next(pos, tmp, head, curr, member) \
|
||||||
for (pos = spa_list_first(curr, __typeof__(*pos), member), \
|
for (pos = spa_list_first(curr, __typeof__(*pos), member), \
|
||||||
|
|
@ -94,7 +94,20 @@ static inline void spa_list_remove(struct spa_list *elem)
|
||||||
tmp = spa_list_next(pos, member))
|
tmp = spa_list_next(pos, member))
|
||||||
|
|
||||||
#define spa_list_for_each_safe(pos, tmp, head, member) \
|
#define spa_list_for_each_safe(pos, tmp, head, member) \
|
||||||
spa_list_for_each_safe_next(pos, tmp, head, head, member) \
|
spa_list_for_each_safe_next(pos, tmp, head, head, member)
|
||||||
|
|
||||||
|
#define spa_list_cursor_start(cursor, head, member) \
|
||||||
|
spa_list_prepend(head, &(cursor).member)
|
||||||
|
|
||||||
|
#define spa_list_for_each_cursor(pos, cursor, head, member) \
|
||||||
|
for(pos = spa_list_first(&(cursor).member, __typeof__(*(pos)), member); \
|
||||||
|
spa_list_remove(&(pos)->member), \
|
||||||
|
spa_list_append(&(cursor).member, &(pos)->member), \
|
||||||
|
!spa_list_is_end(pos, head, member); \
|
||||||
|
pos = spa_list_next(&cursor, member))
|
||||||
|
|
||||||
|
#define spa_list_cursor_end(cursor, member) \
|
||||||
|
spa_list_remove(&(cursor).member)
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
} /* extern "C" */
|
} /* extern "C" */
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue