loop: simplify before and after events

Because the signal can't be removed from the callback we can
simply iterate backwards and then forwards.

The first added hook (the unlock/lock pair) is called last before
going into the poll and first when leaving. This executes all other
callbacks inside a locked situation. And removing them with the lock
is not going to cause problems.
This commit is contained in:
Wim Taymans 2020-09-16 13:20:19 +02:00
parent 854d019343
commit e5f7e040dc
3 changed files with 28 additions and 16 deletions

View file

@ -98,9 +98,17 @@ static inline void spa_list_remove(struct spa_list *elem)
!spa_list_is_end(pos, head, member); \
pos = spa_list_next(pos, member))
#define spa_list_for_each_prev(pos, head, curr, member) \
for (pos = spa_list_last(curr, __typeof__(*pos), member); \
!spa_list_is_end(pos, head, member); \
pos = spa_list_prev(pos, member))
#define spa_list_for_each(pos, head, member) \
spa_list_for_each_next(pos, head, head, member)
#define spa_list_for_each_reverse(pos, head, member) \
spa_list_for_each_prev(pos, head, head, member)
#define spa_list_for_each_safe_next(pos, tmp, head, curr, member) \
for (pos = spa_list_first(curr, __typeof__(*pos), member); \
tmp = spa_list_next(pos, member), \