7 * Simple doubly linked list implementation.
9 * Some of the internal functions ("__xxx") are useful when
10 * manipulating whole lists rather than single entries, as
11 * sometimes we already know the next/prev entries and we can
12 * generate better code by using them directly rather than
13 * using the generic single-entry routines.
17 struct list_head
*next
, *prev
;
20 #define LIST_HEAD_INIT(name) { &(name), &(name) }
22 #define LIST_HEAD(name) \
23 struct list_head name = LIST_HEAD_INIT(name)
25 #define INIT_LIST_HEAD(ptr) do { \
26 (ptr)->next = (ptr); (ptr)->prev = (ptr); \
30 * Insert a new entry between two known consecutive entries.
32 * This is only for internal list manipulation where we know
33 * the prev/next entries already!
35 static __inline__
void __list_add(struct list_head
* new,
36 struct list_head
* prev
,
37 struct list_head
* next
)
46 * Insert a new entry after the specified head..
48 static __inline__
void list_add(struct list_head
*new, struct list_head
*head
)
50 __list_add(new, head
, head
->next
);
54 * Insert a new entry before the specified head..
56 static __inline__
void list_add_tail(struct list_head
*new, struct list_head
*head
)
58 __list_add(new, head
->prev
, head
);
62 * Delete a list entry by making the prev/next entries
63 * point to each other.
65 * This is only for internal list manipulation where we know
66 * the prev/next entries already!
68 static __inline__
void __list_del(struct list_head
* prev
,
69 struct list_head
* next
)
75 static __inline__
void list_del(struct list_head
*entry
)
77 __list_del(entry
->prev
, entry
->next
);
80 static __inline__
int list_empty(struct list_head
*head
)
82 return head
->next
== head
;
86 * Splice in "list" into "head"
88 static __inline__
void list_splice(struct list_head
*list
, struct list_head
*head
)
90 struct list_head
*first
= list
->next
;
93 struct list_head
*last
= list
->prev
;
94 struct list_head
*at
= head
->next
;
104 #define list_entry(ptr, type, member) \
105 ((type *)((char *)(ptr)-(unsigned long)(&((type *)0)->member)))
107 #endif /* __KERNEL__ */