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 INIT_LIST_HEAD(ptr) do { \
23 (ptr)->next = (ptr); (ptr)->prev = (ptr); \
26 #if (!defined(__GNUC__) && !defined(__WATCOMC__))
31 * Insert a new entry between two known consecutive entries.
33 * This is only for internal list manipulation where we know
34 * the prev/next entries already!
36 static __inline__ void __list_add(struct list_head * new,
37 struct list_head * prev,
38 struct list_head * next)
47 * Insert a new entry after the specified head..
49 static __inline__ void list_add(struct list_head *new, struct list_head *head)
51 __list_add(new, head, head->next);
55 * Insert a new entry at the tail
57 static __inline__ void list_add_tail(struct list_head *new, struct list_head *head)
59 __list_add(new, head->prev, head);
63 * Delete a list entry by making the prev/next entries
64 * point to each other.
66 * This is only for internal list manipulation where we know
67 * the prev/next entries already!
69 static __inline__ void __list_del(struct list_head * prev,
70 struct list_head * next)
76 static __inline__ void list_del(struct list_head *entry)
78 __list_del(entry->prev, entry->next);
81 static __inline__ int list_empty(struct list_head *head)
83 return head->next == head;
87 * Splice in "list" into "head"
89 static __inline__ void list_splice(struct list_head *list, struct list_head *head)
91 struct list_head *first = list->next;
94 struct list_head *last = list->prev;
95 struct list_head *at = head->next;
105 #define list_entry(ptr, type, member) \
106 container_of(ptr, type, member)
108 #define list_for_each(pos, head) \
109 for (pos = (head)->next; pos != (head); pos = pos->next)