5 * Simple doubly linked list implementation.
7 * Some of the internal functions ("__xxx") are useful when
8 * manipulating whole lists rather than single entries, as
9 * sometimes we already know the next/prev entries and we can
10 * generate better code by using them directly rather than
11 * using the generic single-entry routines.
15 struct list_head *next, *prev;
18 #define LIST_HEAD_INIT(name) { &(name), &(name) }
20 #define LIST_HEAD(name) \
21 struct list_head name = LIST_HEAD_INIT(name)
23 #define INIT_LIST_HEAD(ptr) do { \
24 (ptr)->next = (ptr); (ptr)->prev = (ptr); \
28 * Insert a new entry between two known consecutive entries.
30 * This is only for internal list manipulation where we know
31 * the prev/next entries already!
33 static __inline__ void __list_add(struct list_head * nnew,
34 struct list_head * prev,
35 struct list_head * next)
44 * list_add - add a new entry
45 * @new: new entry to be added
46 * @head: list head to add it after
48 * Insert a new entry after the specified head.
49 * This is good for implementing stacks.
51 static __inline__ void list_add(struct list_head *nnew, struct list_head *head)
53 __list_add(nnew, head, head->next);
57 * list_add_tail - add a new entry
58 * @nnew: new entry to be added
59 * @head: list head to add it before
61 * Insert a new entry before the specified head.
62 * This is useful for implementing queues.
64 static __inline__ void list_add_tail(struct list_head *nnew, struct list_head *head)
66 __list_add(nnew, head->prev, head);
70 * Delete a list entry by making the prev/next entries
71 * point to each other.
73 * This is only for internal list manipulation where we know
74 * the prev/next entries already!
76 static __inline__ void __list_del(struct list_head * prev,
77 struct list_head * next)
84 * list_del - deletes entry from list.
85 * @entry: the element to delete from the list.
86 * Note: list_empty on entry does not return true after this, the entry is in an undefined state.
88 static __inline__ void list_del(struct list_head *entry)
90 __list_del(entry->prev, entry->next);
94 * list_del_init - deletes entry from list and reinitialize it.
95 * @entry: the element to delete from the list.
97 static __inline__ void list_del_init(struct list_head *entry)
99 __list_del(entry->prev, entry->next);
100 INIT_LIST_HEAD(entry);
104 * list_empty - tests whether a list is empty
105 * @head: the list to test.
107 static __inline__ int list_empty(struct list_head *head)
109 return head->next == head;
113 * list_splice - join two lists
114 * @list: the new list to add.
115 * @head: the place to add it in the first list.
117 static __inline__ void list_splice(struct list_head *list, struct list_head *head)
119 struct list_head *first = list->next;
122 struct list_head *last = list->prev;
123 struct list_head *at = head->next;
134 * list_entry - get the struct for this entry
135 * @ptr: the &struct list_head pointer.
136 * @type: the type of the struct this is embedded in.
137 * @member: the name of the list_struct within the struct.
139 #define list_entry(ptr, type, member) \
140 ((type *)((char *)(ptr)-(unsigned long)(&((type *)0)->member)))
143 * list_for_each - iterate over a list
144 * @pos: the &struct list_head to use as a loop counter.
145 * @head: the head for your list.
147 #define list_for_each(pos, head) \
148 for (pos = (head)->next; pos != (head); \
152 * list_for_each_safe - iterate over a list safe against removal of list entry
153 * @pos: the &struct list_head to use as a loop counter.
154 * @n: another &struct list_head to use as temporary storage
155 * @head: the head for your list.
157 #define list_for_each_safe(pos, n, head) \
158 for (pos = (head)->next, n = pos->next; pos != (head); \
159 pos = n, n = pos->next)
162 * list_for_each_prev - iterate over a list in reverse order
163 * @pos: the &struct list_head to use as a loop counter.
164 * @head: the head for your list.
166 #define list_for_each_prev(pos, head) \
167 for (pos = (head)->prev; pos != (head); \