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.
29 struct list_head
*next
, *prev
;
32 #define LIST_HEAD(name) \
33 struct list_head name = { &name, &name }
35 #define INIT_LIST_HEAD(ptr) do { \
36 (ptr)->next = (ptr); (ptr)->prev = (ptr); \
39 #define CLEAR_LIST_NODE(ptr) do { \
40 (ptr)->next = NULL; (ptr)->prev = NULL; \
44 * Insert a new entry between two known consecutive entries.
46 * This is only for internal list manipulation where we know
47 * the prev/next entries already!
49 static INLINE
void __list_add(struct list_head
*li
,
50 struct list_head
* prev
,
51 struct list_head
* next
)
60 * Insert a new entry after the specified head..
62 static INLINE
void list_add(struct list_head
*li
, struct list_head
*head
)
64 __list_add(li
, head
, head
->next
);
68 * Delete a list entry by making the prev/next entries
69 * point to each other.
71 * This is only for internal list manipulation where we know
72 * the prev/next entries already!
74 static INLINE
void __list_del(struct list_head
* prev
,
75 struct list_head
* next
)
81 static INLINE
void list_del(struct list_head
*entry
)
83 __list_del(entry
->prev
, entry
->next
);
86 static INLINE
int list_empty(struct list_head
*head
)
88 return head
->next
== head
;
92 * Splice in "list" into "head"
94 static INLINE
void list_splice(struct list_head
*list
, struct list_head
*head
)
96 struct list_head
*first
= list
->next
;
99 struct list_head
*last
= list
->prev
;
100 struct list_head
*at
= head
->next
;
110 #define list_entry(ptr, type, member) \
111 ((type *)((char *)(ptr)-offsetof(type, member)))
113 #endif /* _COMMON_LIST_H */