PipeWire 1.4.10

Loading...
Searching...
No Matches
list.h
Go to the documentation of this file.
1/* Simple Plugin API */
2/* SPDX-FileCopyrightText: Copyright © 2018 Wim Taymans */
3/* SPDX-License-Identifier: MIT */
4
5#ifndef SPA_LIST_H
6#define SPA_LIST_H
7
8#ifdef __cplusplus
9 extern "C" {
10#endif
11
12#include <spa/utils/defs.h>
13
14#ifndef SPA_API_LIST
15 #ifdef SPA_API_IMPL
16 #define SPA_API_LIST SPA_API_IMPL
17 #else
18 #define SPA_API_LIST static inline
19 #endif
20#endif
21
26
31
32 struct spa_list {
33 struct spa_list *next;
34 struct spa_list *prev;
35};
36
37#define SPA_LIST_INIT(list) ((struct spa_list){ (list), (list) })
38
39 SPA_API_LIST void spa_list_init(struct spa_list *list)
40{
41 *list = SPA_LIST_INIT(list);
42}
43
44 SPA_API_LIST int spa_list_is_initialized(struct spa_list *list)
45{
46 return !!list->prev;
47}
48
49#define spa_list_is_empty(l) ((l)->next == (l))
50
51 SPA_API_LIST void spa_list_insert(struct spa_list *list, struct spa_list *elem)
52{
53 elem->prev = list;
54 elem->next = list->next;
55 list->next = elem;
56 elem->next->prev = elem;
57}
58
59 SPA_API_LIST void spa_list_insert_list(struct spa_list *list, struct spa_list *other)
60{
61 if (spa_list_is_empty(other))
62 return;
63 other->next->prev = list;
64 other->prev->next = list->next;
65 list->next->prev = other->prev;
66 list->next = other->next;
67}
68
69 SPA_API_LIST void spa_list_remove(struct spa_list *elem)
70{
71 elem->prev->next = elem->next;
72 elem->next->prev = elem->prev;
73}
74
75#define spa_list_first(head, type, member) \
76 SPA_CONTAINER_OF((head)->next, type, member)
77
78#define spa_list_last(head, type, member) \
79 SPA_CONTAINER_OF((head)->prev, type, member)
80
81#define spa_list_append(list, item) \
82 spa_list_insert((list)->prev, item)
83
84#define spa_list_prepend(list, item) \
85 spa_list_insert(list, item)
86
87#define spa_list_is_end(pos, head, member) \
88 (&(pos)->member == (head))
89
90#define spa_list_next(pos, member) \
91 SPA_CONTAINER_OF((pos)->member.next, __typeof__(*(pos)), member)
92
93#define spa_list_prev(pos, member) \
94 SPA_CONTAINER_OF((pos)->member.prev, __typeof__(*(pos)), member)
95
96#define spa_list_consume(pos, head, member) \
97 for ((pos) = spa_list_first(head, __typeof__(*(pos)), member); \
98 !spa_list_is_empty(head); \
99 (pos) = spa_list_first(head, __typeof__(*(pos)), member))
100
101#define spa_list_for_each_next(pos, head, curr, member) \
102 for ((pos) = spa_list_first(curr, __typeof__(*(pos)), member); \
103 !spa_list_is_end(pos, head, member); \
104 (pos) = spa_list_next(pos, member))
105
106#define spa_list_for_each_prev(pos, head, curr, member) \
107 for ((pos) = spa_list_last(curr, __typeof__(*(pos)), member); \
108 !spa_list_is_end(pos, head, member); \
109 (pos) = spa_list_prev(pos, member))
110
111#define spa_list_for_each(pos, head, member) \
112 spa_list_for_each_next(pos, head, head, member)
113
114#define spa_list_for_each_reverse(pos, head, member) \
115 spa_list_for_each_prev(pos, head, head, member)
116
117#define spa_list_for_each_safe_next(pos, tmp, head, curr, member) \
118 for ((pos) = spa_list_first(curr, __typeof__(*(pos)), member); \
119 (tmp) = spa_list_next(pos, member), \
120 !spa_list_is_end(pos, head, member); \
121 (pos) = (tmp))
122
123#define spa_list_for_each_safe_prev(pos, tmp, head, curr, member) \
124 for ((pos) = spa_list_last(curr, __typeof__(*(pos)), member); \
125 (tmp) = spa_list_prev(pos, member), \
126 !spa_list_is_end(pos, head, member); \
127 (pos) = (tmp))
128
129#define spa_list_for_each_safe(pos, tmp, head, member) \
130 spa_list_for_each_safe_next(pos, tmp, head, head, member)
131
132#define spa_list_for_each_safe_reverse(pos, tmp, head, member) \
133 spa_list_for_each_safe_prev(pos, tmp, head, head, member)
134
135#define spa_list_cursor_start(cursor, head, member) \
136 spa_list_prepend(head, &(cursor).member)
137
138#define spa_list_for_each_cursor(pos, cursor, head, member) \
139 for((pos) = spa_list_first(&(cursor).member, __typeof__(*(pos)), member); \
140 spa_list_remove(&(pos)->member), \
141 spa_list_append(&(cursor).member, &(pos)->member), \
142 !spa_list_is_end(pos, head, member); \
143 (pos) = spa_list_next(&(cursor), member))
144
145#define spa_list_cursor_end(cursor, member) \
146 spa_list_remove(&(cursor).member)
147
151
152#ifdef __cplusplus
153} /* extern "C" */
154#endif
155
156#endif /* SPA_LIST_H */
defs.h
spa/utils/defs.h
spa_list_insert
SPA_API_LIST void spa_list_insert(struct spa_list *list, struct spa_list *elem)
Definition list.h:59
spa_list_is_initialized
SPA_API_LIST int spa_list_is_initialized(struct spa_list *list)
Definition list.h:52
spa_list_insert_list
SPA_API_LIST void spa_list_insert_list(struct spa_list *list, struct spa_list *other)
Definition list.h:67
spa_list_init
SPA_API_LIST void spa_list_init(struct spa_list *list)
Definition list.h:47
spa_list_remove
SPA_API_LIST void spa_list_remove(struct spa_list *elem)
Definition list.h:77
spa_list_is_empty
#define spa_list_is_empty(l)
Definition list.h:57
SPA_LIST_INIT
#define SPA_LIST_INIT(list)
Definition list.h:45
SPA_API_LIST
#define SPA_API_LIST
Definition list.h:25
spa_list
Definition list.h:39
spa_list::prev
struct spa_list * prev
Definition list.h:41
spa_list::next
struct spa_list * next
Definition list.h:40