ia64/xen-unstable

view extras/mini-os/include/list.h @ 10843:4f6d858ea570

[PCI] Per-device permissive flag (replaces global permissive flag).
Signed-off-by: Chris Bookholt <hap10@tycho.ncsc.mil>
author kfraser@localhost.localdomain
date Fri Jul 28 12:56:10 2006 +0100 (2006-07-28)
parents 06d84bf87159
children 60828077e175
line source
1 #ifndef _LINUX_LIST_H
2 #define _LINUX_LIST_H
4 /*
5 * Simple doubly linked list implementation.
6 *
7 * Some of the internal functions ("__xxx") are useful when
8 * manipulating whole lists rather than single entries, as
9 * sometimes we already know the next/prev entries and we can
10 * generate better code by using them directly rather than
11 * using the generic single-entry routines.
12 */
14 struct list_head {
15 struct list_head *next, *prev;
16 };
18 #define LIST_HEAD_INIT(name) { &(name), &(name) }
20 #define LIST_HEAD(name) \
21 struct list_head name = LIST_HEAD_INIT(name)
23 #define INIT_LIST_HEAD(ptr) do { \
24 (ptr)->next = (ptr); (ptr)->prev = (ptr); \
25 } while (0)
27 /*
28 * Insert a new entry between two known consecutive entries.
29 *
30 * This is only for internal list manipulation where we know
31 * the prev/next entries already!
32 */
33 static __inline__ void __list_add(struct list_head * new,
34 struct list_head * prev,
35 struct list_head * next)
36 {
37 next->prev = new;
38 new->next = next;
39 new->prev = prev;
40 prev->next = new;
41 }
43 /**
44 * list_add - add a new entry
45 * @new: new entry to be added
46 * @head: list head to add it after
47 *
48 * Insert a new entry after the specified head.
49 * This is good for implementing stacks.
50 */
51 static __inline__ void list_add(struct list_head *new, struct list_head *head)
52 {
53 __list_add(new, head, head->next);
54 }
56 /**
57 * list_add_tail - add a new entry
58 * @new: new entry to be added
59 * @head: list head to add it before
60 *
61 * Insert a new entry before the specified head.
62 * This is useful for implementing queues.
63 */
64 static __inline__ void list_add_tail(struct list_head *new, struct list_head *head)
65 {
66 __list_add(new, head->prev, head);
67 }
69 /*
70 * Delete a list entry by making the prev/next entries
71 * point to each other.
72 *
73 * This is only for internal list manipulation where we know
74 * the prev/next entries already!
75 */
76 static __inline__ void __list_del(struct list_head * prev,
77 struct list_head * next)
78 {
79 next->prev = prev;
80 prev->next = next;
81 }
83 /**
84 * list_del - deletes entry from list.
85 * @entry: the element to delete from the list.
86 * Note: list_empty on entry does not return true after this, the entry is in an undefined state.
87 */
88 static __inline__ void list_del(struct list_head *entry)
89 {
90 __list_del(entry->prev, entry->next);
91 }
93 /**
94 * list_del_init - deletes entry from list and reinitialize it.
95 * @entry: the element to delete from the list.
96 */
97 static __inline__ void list_del_init(struct list_head *entry)
98 {
99 __list_del(entry->prev, entry->next);
100 INIT_LIST_HEAD(entry);
101 }
103 /**
104 * list_empty - tests whether a list is empty
105 * @head: the list to test.
106 */
107 static __inline__ int list_empty(struct list_head *head)
108 {
109 return head->next == head;
110 }
112 /**
113 * list_splice - join two lists
114 * @list: the new list to add.
115 * @head: the place to add it in the first list.
116 */
117 static __inline__ void list_splice(struct list_head *list, struct list_head *head)
118 {
119 struct list_head *first = list->next;
121 if (first != list) {
122 struct list_head *last = list->prev;
123 struct list_head *at = head->next;
125 first->prev = head;
126 head->next = first;
128 last->next = at;
129 at->prev = last;
130 }
131 }
133 /**
134 * list_entry - get the struct for this entry
135 * @ptr: the &struct list_head pointer.
136 * @type: the type of the struct this is embedded in.
137 * @member: the name of the list_struct within the struct.
138 */
139 #define list_entry(ptr, type, member) \
140 ((type *)((char *)(ptr)-(unsigned long)(&((type *)0)->member)))
142 /**
143 * list_for_each - iterate over a list
144 * @pos: the &struct list_head to use as a loop counter.
145 * @head: the head for your list.
146 */
147 #define list_for_each(pos, head) \
148 for (pos = (head)->next; pos != (head); pos = pos->next)
150 /**
151 * list_for_each_safe - iterate over a list safe against removal of list entry
152 * @pos: the &struct list_head to use as a loop counter.
153 * @n: another &struct list_head to use as temporary storage
154 * @head: the head for your list.
155 */
156 #define list_for_each_safe(pos, n, head) \
157 for (pos = (head)->next, n = pos->next; pos != (head); \
158 pos = n, n = pos->next)
160 /**
161 * list_for_each_entry - iterate over list of given type
162 * @pos: the type * to use as a loop counter.
163 * @head: the head for your list.
164 * @member: the name of the list_struct within the struct.
165 */
166 #define list_for_each_entry(pos, head, member) \
167 for (pos = list_entry((head)->next, typeof(*pos), member); \
168 &pos->member != (head); \
169 pos = list_entry(pos->member.next, typeof(*pos), member))
171 /**
172 * list_for_each_entry_safe - iterate over list of given type safe against removal of list entry
173 * @pos: the type * to use as a loop counter.
174 * @n: another type * to use as temporary storage
175 * @head: the head for your list.
176 * @member: the name of the list_struct within the struct.
177 */
178 #define list_for_each_entry_safe(pos, n, head, member) \
179 for (pos = list_entry((head)->next, typeof(*pos), member), \
180 n = list_entry(pos->member.next, typeof(*pos), member); \
181 &pos->member != (head); \
182 pos = n, n = list_entry(n->member.next, typeof(*n), member))
183 #endif /* _LINUX_LIST_H */