cemu
载入中...
搜索中...
未找到
list.h
浏览该文件的文档.
1
13#ifndef LIST_H
14#define LIST_H
15
16
21#ifndef NULL
22#define NULL 0
23#endif
24
25/*
26 * These are non-NULL pointers that will result in page faults
27 * under normal circumstances, used to verify that nobody uses
28 * non-initialized list entries.
29 */
30#define LIST_POISON1 ((void *) 0x00100100)
31#define LIST_POISON2 ((void *) 0x00200200)
32
33/*
34 * Simple doubly linked list implementation.
35 *
36 * Some of the internal functions ("__xxx") are useful when
37 * manipulating whole lists rather than single entries, as
38 * sometimes we already know the next/prev entries and we can
39 * generate better code by using them directly rather than
40 * using the generic single-entry routines.
41 */
42
43struct list_head {
44 struct list_head *next, *prev;
45};
46
47#define LIST_HEAD_INIT(name) { &(name), &(name) }
48
49#define LIST_HEAD(name) \
50 struct list_head name = LIST_HEAD_INIT(name)
51
52#define INIT_LIST_HEAD(ptr) do { \
53 (ptr)->next = (ptr); (ptr)->prev = (ptr); \
54} while (0)
55
56/*
57 * Insert a l_new entry between two known consecutive entries.
58 *
59 * This is only for internal list manipulation where we know
60 * the prev/next entries already!
61 */
62void __list_add(struct list_head * l_new,
63 struct list_head * prev,
64 struct list_head * next);
65
74void list_add(struct list_head *l_new, struct list_head *head);
75
84void list_add_tail(struct list_head *l_new, struct list_head *head);
85
86/*
87 * Delete a list entry by making the prev/next entries
88 * point to each other.
89 *
90 * This is only for internal list manipulation where we know
91 * the prev/next entries already!
92 */
93void __list_del(struct list_head * prev,
94 struct list_head * next);
95
101void list_del(struct list_head *entry);
102
107void list_del_init(struct list_head *entry);
108
113int list_empty(struct list_head *head);
114
120void list_splice(struct list_head *list, struct list_head *head);
121
128#define list_entry(ptr, type, member) \
129 ((type *)((char *)(ptr)-(unsigned long)(&((type *)0)->member)))
130
139#define list_first_entry(ptr, type, member) \
140 list_entry((ptr)->next, type, member)
141
150#define list_last_entry(ptr, type, member) \
151 list_entry((ptr)->prev, type, member)
152
161#define list_first_entry_or_null(ptr, type, member) \
162 (!list_empty(ptr) ? list_first_entry(ptr, type, member) : NULL)
163
169#define list_for_each(pos, head) \
170 for (pos = (head)->next; pos != (head); pos = pos->next)
171
178#define list_for_each_safe(pos, n, head) \
179 for (pos = (head)->next, n = pos->next; pos != (head); \
180 pos = n, n = pos->next)
181
187#define list_for_each_prev(pos, head) \
188 for (pos = (head)->prev; pos != (head); pos = pos->prev)
189
190/*
191 * Double linked lists with a single pointer list head.
192 * Mostly useful for hash tables where the two pointer list head is
193 * too wasteful.
194 * You lose the ability to access the tail in O(1).
195 */
196
198 struct hlist_node *next, **pprev;
199};
200
202 struct hlist_node *first;
203};
204
205#define INIT_HLIST_HEAD(ptr) ((ptr)->first = NULL)
206#define INIT_HLIST_NODE(h) \
207{ \
208 h->next = NULL; \
209 h->pprev = NULL; \
210}
211
212#define hlist_unhashed(h) (!h->pprev)
213
214#define hlist_empty(h) (!h->first)
215
216void hlist_del(struct hlist_node *n);
217void hlist_del_init(struct hlist_node *n);
218void hlist_add_head(struct hlist_node *n, struct hlist_head *h);
219
220/* next must be != NULL */
221void hlist_add_before(struct hlist_node *n, struct hlist_node *next);
222void hlist_add_behind(struct hlist_node *n, struct hlist_node *prev);
223/* after that we'll appear to be on some hlist and hlist_del will work */
224void hlist_add_fake(struct hlist_node *n);
225int hlist_fake(struct hlist_node *h);
226
227/*
228 * Move a list from one list head to another. Fixup the pprev
229 * reference of the first entry if it exists.
230 */
231void hlist_move_list(struct hlist_head *old, struct hlist_head *l_new);
232
233#define hlist_entry(ptr, type, member) \
234 ((type *)((char *)(ptr)-(unsigned long)(&((type *)0)->member)))
235
236#define hlist_for_each(pos, head) \
237 for (pos = (head)->first; pos ; pos = pos->next)
238
239#define hlist_for_each_safe(pos, n, head) \
240 for (pos = (head)->first; pos && ({ n = pos->next; 1; }); pos = n)
241
242
243#endif // _WHEELC_LIST_H_
int list_empty(struct list_head *head)
Definition list.c:95
void list_splice(struct list_head *list, struct list_head *head)
Definition list.c:105
void list_del_init(struct list_head *entry)
Definition list.c:85
void list_add(struct list_head *l_new, struct list_head *head)
Definition list.c:39
void list_add_tail(struct list_head *l_new, struct list_head *head)
Definition list.c:52
void list_del(struct list_head *entry)
Definition list.c:76
Definition list.h:201
Definition list.h:197
Definition list.h:43