2 * Copyright 2001, 2002, 2003 David Mansfield and Cobite, Inc.
3 * See COPYING file for license information
10 * Stolen from linux-2.1.131
11 * All comments from the original source unless otherwise noted
12 * Added: the CLEAR_LIST_NODE macro
16 * Simple doubly linked list implementation.
18 * Some of the internal functions ("__xxx") are useful when
19 * manipulating whole lists rather than single entries, as
20 * sometimes we already know the next/prev entries and we can
21 * generate better code by using them directly rather than
22 * using the generic single-entry routines.
28 struct list_head
*next
, *prev
;
31 #define LIST_HEAD(name) \
32 struct list_head name = { &name, &name }
34 #define INIT_LIST_HEAD(ptr) do { \
35 (ptr)->next = (ptr); (ptr)->prev = (ptr); \
38 #define CLEAR_LIST_NODE(ptr) do { \
39 (ptr)->next = NULL; (ptr)->prev = NULL; \
43 * Insert a new entry between two known consecutive entries.
45 * This is only for internal list manipulation where we know
46 * the prev/next entries already!
48 static INLINE
void __list_add(struct list_head
*li
,
49 struct list_head
* prev
,
50 struct list_head
* next
)
59 * Insert a new entry after the specified head..
61 static INLINE
void list_add(struct list_head
*li
, struct list_head
*head
)
63 __list_add(li
, head
, head
->next
);
67 * Delete a list entry by making the prev/next entries
68 * point to each other.
70 * This is only for internal list manipulation where we know
71 * the prev/next entries already!
73 static INLINE
void __list_del(struct list_head
* prev
,
74 struct list_head
* next
)
80 static INLINE
void list_del(struct list_head
*entry
)
82 __list_del(entry
->prev
, entry
->next
);
85 static INLINE
int list_empty(struct list_head
*head
)
87 return head
->next
== head
;
91 * Splice in "list" into "head"
93 static INLINE
void list_splice(struct list_head
*list
, struct list_head
*head
)
95 struct list_head
*first
= list
->next
;
98 struct list_head
*last
= list
->prev
;
99 struct list_head
*at
= head
->next
;
109 #define list_entry(ptr, type, member) \
110 ((type *)((char *)(ptr)-(unsigned long)(&((type *)0)->member)))
112 #endif /* _COMMON_LIST_H */