Import 2.3.25pre1
[davej-history.git] / include / linux / list.h
blob656aacc2a0ddd03a2209a2d3c231e36dc3c5488f
1 #ifndef _LINUX_LIST_H
2 #define _LINUX_LIST_H
4 #ifdef __KERNEL__
6 /*
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.
16 struct list_head {
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); \
27 } while (0)
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)
39 next->prev = new;
40 new->next = next;
41 new->prev = prev;
42 prev->next = new;
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)
71 next->prev = prev;
72 prev->next = 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;
92 if (first != list) {
93 struct list_head *last = list->prev;
94 struct list_head *at = head->next;
96 first->prev = head;
97 head->next = first;
99 last->next = at;
100 at->prev = last;
104 #define list_entry(ptr, type, member) \
105 ((type *)((char *)(ptr)-(unsigned long)(&((type *)0)->member)))
107 #endif /* __KERNEL__ */
109 #endif