5 #define INLINE __inline
10 /* This file is from Linux Kernel (include/linux/list.h)
11 * and modified by simply removing hardware prefetching of list items.
12 * Here by copyright, credits attributed to where ever they belong.
13 * Get from http://isis.poly.edu/kulesh/stuff/src/klist/
17 * Simple doubly linked list implementation.
19 * Some of the internal functions ("__xxx") are useful when
20 * manipulating whole lists rather than single entries, as
21 * sometimes we already know the next/prev entries and we can
22 * generate better code by using them directly rather than
23 * using the generic single-entry routines.
27 struct list_head *next, *prev;
30 #define LIST_HEAD_INIT(name) { &(name), &(name) }
32 #define LIST_HEAD(name) \
33 struct list_head name = LIST_HEAD_INIT(name)
35 #define INIT_LIST_HEAD(ptr) do { \
36 (ptr)->next = (ptr); (ptr)->prev = (ptr); \
40 * Insert a newl entry between two known consecutive entries.
42 * This is only for internal list manipulation where we know
43 * the prev/next entries already!
45 static INLINE void __list_add(struct list_head *newl,
46 struct list_head *prev,
47 struct list_head *next)
56 * list_add - add a newl entry
57 * @newl: newl entry to be added
58 * @head: list head to add it after
60 * Insert a newl entry after the specified head.
61 * This is good for implementing stacks.
63 static INLINE void list_add(struct list_head *newl, struct list_head *head)
65 __list_add(newl, head, head->next);
69 * list_add_tail - add a newl entry
70 * @newl: newl entry to be added
71 * @head: list head to add it before
73 * Insert a newl entry before the specified head.
74 * This is useful for implementing queues.
76 static INLINE void list_add_tail(struct list_head *newl, struct list_head *head)
78 __list_add(newl, head->prev, head);
82 * Delete a list entry by making the prev/next entries
83 * point to each other.
85 * This is only for internal list manipulation where we know
86 * the prev/next entries already!
88 static INLINE void __list_del(struct list_head *prev, struct list_head *next)
95 * list_del - deletes entry from list.
96 * @entry: the element to delete from the list.
97 * Note: list_empty on entry does not return true after this, the entry is in an undefined state.
99 static INLINE void list_del(struct list_head *entry)
101 __list_del(entry->prev, entry->next);
103 entry->prev = (struct list_head *) 0;
107 * list_del_init - deletes entry from list and reinitialize it.
108 * @entry: the element to delete from the list.
110 static INLINE void list_del_init(struct list_head *entry)
112 __list_del(entry->prev, entry->next);
113 INIT_LIST_HEAD(entry);
117 * list_move - delete from one list and add as another's head
118 * @list: the entry to move
119 * @head: the head that will precede our entry
121 static INLINE void list_move(struct list_head *list, struct list_head *head)
123 __list_del(list->prev, list->next);
124 list_add(list, head);
128 * list_move_tail - delete from one list and add as another's tail
129 * @list: the entry to move
130 * @head: the head that will follow our entry
132 static INLINE void list_move_tail(struct list_head *list,
133 struct list_head *head)
135 __list_del(list->prev, list->next);
136 list_add_tail(list, head);
140 * list_empty - tests whether a list is empty
141 * @head: the list to test.
143 static INLINE int list_empty(struct list_head *head)
145 return head->next == head;
148 static INLINE void __list_splice(struct list_head *list,
149 struct list_head *head)
151 struct list_head *first = list->next;
152 struct list_head *last = list->prev;
153 struct list_head *at = head->next;
163 * list_splice - join two lists
164 * @list: the newl list to add.
165 * @head: the place to add it in the first list.
167 static INLINE void list_splice(struct list_head *list, struct list_head *head)
169 if (!list_empty(list))
170 __list_splice(list, head);
174 * list_splice_init - join two lists and reinitialise the emptied list.
175 * @list: the newl list to add.
176 * @head: the place to add it in the first list.
178 * The list at @list is reinitialised
180 static INLINE void list_splice_init(struct list_head *list,
181 struct list_head *head)
183 if (!list_empty(list)) {
184 __list_splice(list, head);
185 INIT_LIST_HEAD(list);
190 * list_entry - get the struct for this entry
191 * @ptr: the &struct list_head pointer.
192 * @type: the type of the struct this is embedded in.
193 * @member: the name of the list_struct within the struct.
195 #define list_entry(ptr, type, member) \
196 ((type *)((char *)(ptr)-(unsigned long)(&((type *)0)->member)))
199 * list_for_each - iterate over a list
200 * @pos: the &struct list_head to use as a loop counter.
201 * @head: the head for your list.
203 #define list_for_each(pos, head) \
204 for (pos = (head)->next; pos != (head); \
207 * list_for_each_prev - iterate over a list backwards
208 * @pos: the &struct list_head to use as a loop counter.
209 * @head: the head for your list.
211 #define list_for_each_prev(pos, head) \
212 for (pos = (head)->prev; pos != (head); \
216 * list_for_each_safe - iterate over a list safe against removal of list entry
217 * @pos: the &struct list_head to use as a loop counter.
218 * @n: another &struct list_head to use as temporary storage
219 * @head: the head for your list.
221 #define list_for_each_safe(pos, n, head) \
222 for (pos = (head)->next, n = pos->next; pos != (head); \
223 pos = n, n = pos->next)
226 * list_for_each_entry - iterate over list of given type
227 * @pos: the type * to use as a loop counter.
228 * @head: the head for your list.
229 * @member: the name of the list_struct within the struct.
231 #define list_for_each_entry(pos, head, member) \
232 for (pos = list_entry((head)->next, typeof(*pos), member); \
233 &pos->member != (head); \
234 pos = list_entry(pos->member.next, typeof(*pos), member))
237 * list_for_each_entry_safe - iterate over list of given type safe against removal of list entry
238 * @pos: the type * to use as a loop counter.
239 * @n: another type * to use as temporary storage
240 * @head: the head for your list.
241 * @member: the name of the list_struct within the struct.
243 #define list_for_each_entry_safe(pos, n, head, member) \
244 for (pos = list_entry((head)->next, typeof(*pos), member), \
245 n = list_entry(pos->member.next, typeof(*pos), member); \
246 &pos->member != (head); \
247 pos = n, n = list_entry(n->member.next, typeof(*n), member))