debuggers.hg

view xen/include/xen/list.h @ 3654:552dd1f1c64c

bitkeeper revision 1.1159.238.5 (4200df8a5A2pMKPYmS5iOV3Q8d2zIw)

Cset exclude: iap10@labyrinth.cl.cam.ac.uk|ChangeSet|20050202130109|29824
author iap10@labyrinth.cl.cam.ac.uk
date Wed Feb 02 14:11:22 2005 +0000 (2005-02-02)
parents 49103eca5edb
children 0ef6e8e6e85d
line source
1 #ifndef _LINUX_LIST_H
2 #define _LINUX_LIST_H
4 #include <xen/lib.h>
6 /*
7 * Simple doubly linked list implementation.
8 *
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.
14 */
16 struct list_head {
17 struct list_head *next, *prev;
18 };
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)
29 /*
30 * Insert a new entry between two known consecutive entries.
31 *
32 * This is only for internal list manipulation where we know
33 * the prev/next entries already!
34 */
35 static __inline__ void __list_add(struct list_head * new,
36 struct list_head * prev,
37 struct list_head * next)
38 {
39 next->prev = new;
40 new->next = next;
41 new->prev = prev;
42 prev->next = new;
43 }
45 /**
46 * list_add - add a new entry
47 * @new: new entry to be added
48 * @head: list head to add it after
49 *
50 * Insert a new entry after the specified head.
51 * This is good for implementing stacks.
52 */
53 static __inline__ void list_add(struct list_head *new, struct list_head *head)
54 {
55 __list_add(new, head, head->next);
56 }
58 /**
59 * list_add_tail - add a new entry
60 * @new: new entry to be added
61 * @head: list head to add it before
62 *
63 * Insert a new entry before the specified head.
64 * This is useful for implementing queues.
65 */
66 static __inline__ void list_add_tail(struct list_head *new, struct list_head *head)
67 {
68 __list_add(new, head->prev, head);
69 }
71 /*
72 * Delete a list entry by making the prev/next entries
73 * point to each other.
74 *
75 * This is only for internal list manipulation where we know
76 * the prev/next entries already!
77 */
78 static __inline__ void __list_del(struct list_head * prev,
79 struct list_head * next)
80 {
81 next->prev = prev;
82 prev->next = next;
83 }
85 /**
86 * list_del - deletes entry from list.
87 * @entry: the element to delete from the list.
88 * Note: list_empty on entry does not return true after this, the entry is in an undefined state.
89 */
90 static __inline__ void list_del(struct list_head *entry)
91 {
92 ASSERT(entry->next->prev == entry);
93 ASSERT(entry->prev->next == entry);
94 __list_del(entry->prev, entry->next);
95 }
97 /**
98 * list_del_init - deletes entry from list and reinitialize it.
99 * @entry: the element to delete from the list.
100 */
101 static __inline__ void list_del_init(struct list_head *entry)
102 {
103 __list_del(entry->prev, entry->next);
104 INIT_LIST_HEAD(entry);
105 }
107 /**
108 * list_empty - tests whether a list is empty
109 * @head: the list to test.
110 */
111 static __inline__ int list_empty(struct list_head *head)
112 {
113 return head->next == head;
114 }
116 /**
117 * list_splice - join two lists
118 * @list: the new list to add.
119 * @head: the place to add it in the first list.
120 */
121 static __inline__ void list_splice(struct list_head *list, struct list_head *head)
122 {
123 struct list_head *first = list->next;
125 if (first != list) {
126 struct list_head *last = list->prev;
127 struct list_head *at = head->next;
129 first->prev = head;
130 head->next = first;
132 last->next = at;
133 at->prev = last;
134 }
135 }
137 /**
138 * list_entry - get the struct for this entry
139 * @ptr: the &struct list_head pointer.
140 * @type: the type of the struct this is embedded in.
141 * @member: the name of the list_struct within the struct.
142 */
143 #define list_entry(ptr, type, member) \
144 ((type *)((char *)(ptr)-(unsigned long)(&((type *)0)->member)))
146 /**
147 * list_for_each - iterate over a list
148 * @pos: the &struct list_head to use as a loop counter.
149 * @head: the head for your list.
150 */
151 #define list_for_each(pos, head) \
152 for (pos = (head)->next; pos != (head); pos = pos->next)
154 /**
155 * list_for_each_safe - iterate over a list safe against removal of list entry
156 * @pos: the &struct list_head to use as a loop counter.
157 * @n: another &struct list_head to use as temporary storage
158 * @head: the head for your list.
159 */
160 #define list_for_each_safe(pos, n, head) \
161 for (pos = (head)->next, n = pos->next; pos != (head); \
162 pos = n, n = pos->next)
164 /**
165 * list_for_each_entry - iterate over list of given type
166 * @pos: the type * to use as a loop counter.
167 * @head: the head for your list.
168 * @member: the name of the list_struct within the struct.
169 */
170 #define list_for_each_entry(pos, head, member) \
171 for (pos = list_entry((head)->next, typeof(*pos), member), \
172 prefetch(pos->member.next); \
173 &pos->member != (head); \
174 pos = list_entry(pos->member.next, typeof(*pos), member), \
175 prefetch(pos->member.next))
177 #endif /* _LINUX_LIST_H */