move eventfd stuff out to own file
[trinity.git] / include / list.h
blob911658e5ed708c7c06f8274569daed30535b9c34
1 #pragma once
3 #include <stdio.h>
5 /*
6 * Simple linked-list routines, based on functions of the same name from the Linux kernel.
7 */
9 struct list_head {
10 struct list_head *next, *prev;
13 static inline void INIT_LIST_HEAD(struct list_head *list)
15 list->next = list;
16 list->prev = list;
19 static inline int list_empty(const struct list_head *head)
21 return head->next == head;
24 static inline void __list_add(struct list_head *new,
25 struct list_head *prev,
26 struct list_head *next)
28 next->prev = new;
29 new->next = next;
30 new->prev = prev;
31 prev->next = new;
34 static inline void list_add(struct list_head *new, struct list_head *head)
36 __list_add(new, head, head->next);
39 static inline void list_add_tail(struct list_head *new, struct list_head *head)
41 __list_add(new, head->prev, head);
44 static inline void __list_del(struct list_head * prev, struct list_head * next)
46 next->prev = prev;
47 prev->next = next;
50 static inline void list_del(struct list_head *entry)
52 __list_del(entry->prev, entry->next);
53 entry->next = entry->prev = NULL;
56 #define list_for_each(pos, head) \
57 for (pos = (head)->next; pos != (head); pos = pos->next)