5 * This linked list implementation is the same as linux kernel implementation.
6 * Refer to the linux kernel documentation for usage.
10 struct list_head *next, *prev;
13 #define INIT_LIST_HEAD(ptr) do { \
14 (ptr)->next = (ptr); (ptr)->prev = (ptr); \
18 * Insert a new entry between two known consecutive entries.
20 * This is only for internal list manipulation where we know
21 * the prev/next entries already!
23 static inline void __list_add(struct list_head * new_entry,
24 struct list_head * prev,
25 struct list_head * next)
27 next->prev = new_entry;
28 new_entry->next = next;
29 new_entry->prev = prev;
30 prev->next = new_entry;
34 * list_add - add a new entry
35 * @new: new entry to be added
36 * @head: list head to add it after
38 * Insert a new entry after the specified head.
39 * This is good for implementing stacks.
41 static inline void list_add(struct list_head *new_entry, struct list_head *head)
43 __list_add(new_entry, head, head->next);
47 * list_add_tail - add a new entry
48 * @new: new entry to be added
49 * @head: list head to add it before
51 * Insert a new entry before the specified head.
52 * This is useful for implementing queues.
54 static inline void list_add_tail(struct list_head *new_entry, struct list_head *head)
56 __list_add(new_entry, head->prev, head);
60 * Delete a list entry by making the prev/next entries
61 * point to each other.
63 * This is only for internal list manipulation where we know
64 * the prev/next entries already!
66 static inline void __list_del(struct list_head * prev,
67 struct list_head * next)
74 * list_del - deletes entry from list.
75 * @entry: the element to delete from the list.
76 * Note: list_empty on entry does not return true after this, the entry is in an undefined state.
78 static inline void list_del(struct list_head *entry)
80 __list_del(entry->prev, entry->next);
81 entry->next = entry->prev = 0;
85 * list_del_init - deletes entry from list and reinitialize it.
86 * @entry: the element to delete from the list.
88 static inline void list_del_init(struct list_head *entry)
90 __list_del(entry->prev, entry->next);
91 INIT_LIST_HEAD(entry);
95 * list_empty - tests whether a list is empty
96 * @head: the list to test.
98 static inline int list_empty(struct list_head *head)
100 return head->next == head;
104 * list_entry - get the struct for this entry
105 * @ptr: the &struct list_head pointer.
106 * @type: the type of the struct this is embedded in.
107 * @member: the name of the list_struct within the struct.
109 #define list_entry(ptr, type, member) \
110 ((type *)((char *)(ptr)-(unsigned long)(&((type *)0)->member)))
113 * list_for_each - iterate over a list
114 * @pos: the &struct list_head to use as a loop counter.
115 * @head: the head for your list.
117 #define list_for_each(pos, head) \
118 for (pos = (head)->next; pos != (head); \
122 * list_for_each_safe - iterate over a list safe against removal of list entry
123 * @pos: the &struct list_head to use as a loop counter.
124 * @n: another &struct list_head to use as temporary storage
125 * @head: the head for your list.
127 #define list_for_each_safe(pos, n, head) \
128 for (pos = (head)->next, n = pos->next; pos != (head); \
129 pos = n, n = pos->next)