1 /* vi: set sw=4 ts=4: */
6 * Simple doubly linked list implementation.
8 * Some of the internal functions ("__xxx") are useful when
9 * manipulating whole lists rather than single entries, as
10 * sometimes we already know the next/prev entries and we can
11 * generate better code by using them directly rather than
12 * using the generic single-entry routines.
16 struct list_head
*next
, *prev
;
19 #define LIST_HEAD_INIT(name) { &(name), &(name) }
21 #define LIST_HEAD(name) \
22 struct list_head name = { &name, &name }
24 #define INIT_LIST_HEAD(ptr) do { \
25 (ptr)->next = (ptr); (ptr)->prev = (ptr); \
28 #if (!defined(__GNUC__) && !defined(__WATCOMC__))
33 * Insert a new entry between two known consecutive entries.
35 * This is only for internal list manipulation where we know
36 * the prev/next entries already!
38 static __inline__
void __list_add(struct list_head
* new,
39 struct list_head
* prev
,
40 struct list_head
* next
)
49 * Insert a new entry after the specified head..
51 static __inline__
void list_add(struct list_head
*new, struct list_head
*head
)
53 __list_add(new, head
, head
->next
);
57 * Insert a new entry at the tail
59 static __inline__
void list_add_tail(struct list_head
*new, struct list_head
*head
)
61 __list_add(new, head
->prev
, head
);
65 * Delete a list entry by making the prev/next entries
66 * point to each other.
68 * This is only for internal list manipulation where we know
69 * the prev/next entries already!
71 static __inline__
void __list_del(struct list_head
* prev
,
72 struct list_head
* next
)
78 static __inline__
void list_del(struct list_head
*entry
)
80 __list_del(entry
->prev
, entry
->next
);
83 static __inline__
int list_empty(struct list_head
*head
)
85 return head
->next
== head
;
89 * Splice in "list" into "head"
91 static __inline__
void list_splice(struct list_head
*list
, struct list_head
*head
)
93 struct list_head
*first
= list
->next
;
96 struct list_head
*last
= list
->prev
;
97 struct list_head
*at
= head
->next
;
107 #define list_entry(ptr, type, member) \
108 ((type *)((char *)(ptr)-(unsigned long)(&((type *)0)->member)))
110 #define list_for_each(pos, head) \
111 for (pos = (head)->next; pos != (head); pos = pos->next)