Add memtest support.
[syslinux-debian/hramrach.git] / com32 / include / linux / list.h
blob157ded10fb72e758d4376b295b96600d6542b036
1 // This list structure implementation is adapted from the list implementation
2 // on the Linux kernel.
4 // Original source:
5 // http://git.kernel.org/?p=linux/kernel/git/stable/linux-2.6.25.y.git;a=blob_plain;f=include/linux/list.h;hb=HEAD
7 #ifndef _LINUX_LIST_H
8 #define _LINUX_LIST_H
11 * Simple doubly linked list implementation.
13 * Some of the internal functions ("__xxx") are useful when
14 * manipulating whole lists rather than single entries, as
15 * sometimes we already know the next/prev entries and we can
16 * generate better code by using them directly rather than
17 * using the generic single-entry routines.
20 #include <stdlib.h>
21 #include <stddef.h>
23 struct list_head {
24 struct list_head *next, *prev;
27 #define LIST_HEAD_INIT(name) { &(name), &(name) }
29 #define LIST_HEAD(name) \
30 struct list_head name = LIST_HEAD_INIT(name)
32 static inline void INIT_LIST_HEAD(struct list_head *list)
34 list->next = list;
35 list->prev = list;
39 * Insert a new entry between two known consecutive entries.
41 * This is only for internal list manipulation where we know
42 * the prev/next entries already!
44 static inline void __list_add(struct list_head *new,
45 struct list_head *prev,
46 struct list_head *next)
48 next->prev = new;
49 new->next = next;
50 new->prev = prev;
51 prev->next = new;
54 /**
55 * list_add - add a new entry
56 * @new: new entry to be added
57 * @head: list head to add it after
59 * Insert a new entry after the specified head.
60 * This is good for implementing stacks.
62 static inline void list_add(struct list_head *new, struct list_head *head)
64 __list_add(new, head, head->next);
69 /**
70 * list_add_tail - add a new entry
71 * @new: new entry to be added
72 * @head: list head to add it before
74 * Insert a new entry before the specified head.
75 * This is useful for implementing queues.
77 static inline void list_add_tail(struct list_head *new, struct list_head *head)
79 __list_add(new, head->prev, head);
84 * Delete a list entry by making the prev/next entries
85 * point to each other.
87 * This is only for internal list manipulation where we know
88 * the prev/next entries already!
90 static inline void __list_del(struct list_head * prev, struct list_head * next)
92 next->prev = prev;
93 prev->next = next;
96 /**
97 * list_del - deletes entry from list.
98 * @entry: the element to delete from the list.
99 * Note: list_empty() on entry does not return true after this, the entry is
100 * in an undefined state.
102 static inline void list_del(struct list_head *entry)
104 __list_del(entry->prev, entry->next);
105 entry->next = NULL;
106 entry->prev = NULL;
110 * list_replace - replace old entry by new one
111 * @old : the element to be replaced
112 * @new : the new element to insert
114 * If @old was empty, it will be overwritten.
116 static inline void list_replace(struct list_head *old,
117 struct list_head *new)
119 new->next = old->next;
120 new->next->prev = new;
121 new->prev = old->prev;
122 new->prev->next = new;
125 static inline void list_replace_init(struct list_head *old,
126 struct list_head *new)
128 list_replace(old, new);
129 INIT_LIST_HEAD(old);
133 * list_del_init - deletes entry from list and reinitialize it.
134 * @entry: the element to delete from the list.
136 static inline void list_del_init(struct list_head *entry)
138 __list_del(entry->prev, entry->next);
139 INIT_LIST_HEAD(entry);
143 * list_move - delete from one list and add as another's head
144 * @list: the entry to move
145 * @head: the head that will precede our entry
147 static inline void list_move(struct list_head *list, struct list_head *head)
149 __list_del(list->prev, list->next);
150 list_add(list, head);
154 * list_move_tail - delete from one list and add as another's tail
155 * @list: the entry to move
156 * @head: the head that will follow our entry
158 static inline void list_move_tail(struct list_head *list,
159 struct list_head *head)
161 __list_del(list->prev, list->next);
162 list_add_tail(list, head);
166 * list_is_last - tests whether @list is the last entry in list @head
167 * @list: the entry to test
168 * @head: the head of the list
170 static inline int list_is_last(const struct list_head *list,
171 const struct list_head *head)
173 return list->next == head;
177 * list_empty - tests whether a list is empty
178 * @head: the list to test.
180 static inline int list_empty(const struct list_head *head)
182 return head->next == head;
186 * list_empty_careful - tests whether a list is empty and not being modified
187 * @head: the list to test
189 * Description:
190 * tests whether a list is empty _and_ checks that no other CPU might be
191 * in the process of modifying either member (next or prev)
193 * NOTE: using list_empty_careful() without synchronization
194 * can only be safe if the only activity that can happen
195 * to the list entry is list_del_init(). Eg. it cannot be used
196 * if another CPU could re-list_add() it.
198 static inline int list_empty_careful(const struct list_head *head)
200 struct list_head *next = head->next;
201 return (next == head) && (next == head->prev);
204 static inline void __list_splice(struct list_head *list,
205 struct list_head *head)
207 struct list_head *first = list->next;
208 struct list_head *last = list->prev;
209 struct list_head *at = head->next;
211 first->prev = head;
212 head->next = first;
214 last->next = at;
215 at->prev = last;
219 * list_splice - join two lists
220 * @list: the new list to add.
221 * @head: the place to add it in the first list.
223 static inline void list_splice(struct list_head *list, struct list_head *head)
225 if (!list_empty(list))
226 __list_splice(list, head);
230 * list_splice_init - join two lists and reinitialise the emptied list.
231 * @list: the new list to add.
232 * @head: the place to add it in the first list.
234 * The list at @list is reinitialised
236 static inline void list_splice_init(struct list_head *list,
237 struct list_head *head)
239 if (!list_empty(list)) {
240 __list_splice(list, head);
241 INIT_LIST_HEAD(list);
246 * list_entry - get the struct for this entry
247 * @ptr: the &struct list_head pointer.
248 * @type: the type of the struct this is embedded in.
249 * @member: the name of the list_struct within the struct.
251 #define list_entry(ptr, type, member) \
252 container_of(ptr, type, member)
255 * list_first_entry - get the first element from a list
256 * @ptr: the list head to take the element from.
257 * @type: the type of the struct this is embedded in.
258 * @member: the name of the list_struct within the struct.
260 * Note, that list is expected to be not empty.
262 #define list_first_entry(ptr, type, member) \
263 list_entry((ptr)->next, type, member)
266 * list_for_each - iterate over a list
267 * @pos: the &struct list_head to use as a loop cursor.
268 * @head: the head for your list.
270 #define list_for_each(pos, head) \
271 for (pos = (head)->next; pos != (head); \
272 pos = pos->next)
275 * __list_for_each - iterate over a list
276 * @pos: the &struct list_head to use as a loop cursor.
277 * @head: the head for your list.
279 * This variant differs from list_for_each() in that it's the
280 * simplest possible list iteration code, no prefetching is done.
281 * Use this for code that knows the list to be very short (empty
282 * or 1 entry) most of the time.
284 #define __list_for_each(pos, head) \
285 for (pos = (head)->next; pos != (head); pos = pos->next)
288 * list_for_each_prev - iterate over a list backwards
289 * @pos: the &struct list_head to use as a loop cursor.
290 * @head: the head for your list.
292 #define list_for_each_prev(pos, head) \
293 for (pos = (head)->prev; pos != (head); \
294 pos = pos->prev)
297 * list_for_each_safe - iterate over a list safe against removal of list entry
298 * @pos: the &struct list_head to use as a loop cursor.
299 * @n: another &struct list_head to use as temporary storage
300 * @head: the head for your list.
302 #define list_for_each_safe(pos, n, head) \
303 for (pos = (head)->next, n = pos->next; pos != (head); \
304 pos = n, n = pos->next)
307 * list_for_each_prev_safe - iterate over a list backwards safe against removal of list entry
308 * @pos: the &struct list_head to use as a loop cursor.
309 * @n: another &struct list_head to use as temporary storage
310 * @head: the head for your list.
312 #define list_for_each_prev_safe(pos, n, head) \
313 for (pos = (head)->prev, n = pos->prev; \
314 pos != (head); \
315 pos = n, n = pos->prev)
318 * list_for_each_entry - iterate over list of given type
319 * @pos: the type * to use as a loop cursor.
320 * @head: the head for your list.
321 * @member: the name of the list_struct within the struct.
323 #define list_for_each_entry(pos, head, member) \
324 for (pos = list_entry((head)->next, typeof(*pos), member); \
325 &pos->member != (head); \
326 pos = list_entry(pos->member.next, typeof(*pos), member))
329 * list_for_each_entry_safe - iterate over list of given type safe against removal of list entry
330 * @pos: the type * to use as a loop cursor.
331 * @n: another type * to use as temporary storage
332 * @head: the head for your list.
333 * @member: the name of the list_struct within the struct.
335 #define list_for_each_entry_safe(pos, n, head, member) \
336 for (pos = list_entry((head)->next, typeof(*pos), member), \
337 n = list_entry(pos->member.next, typeof(*pos), member); \
338 &pos->member != (head); \
339 pos = n, n = list_entry(n->member.next, typeof(*n), member))
342 * list_for_each_entry_reverse - iterate backwards over list of given type.
343 * @pos: the type * to use as a loop cursor.
344 * @head: the head for your list.
345 * @member: the name of the list_struct within the struct.
347 #define list_for_each_entry_reverse(pos, head, member) \
348 for (pos = list_entry((head)->prev, typeof(*pos), member); \
349 &pos->member != (head); \
350 pos = list_entry(pos->member.prev, typeof(*pos), member))
353 * list_prepare_entry - prepare a pos entry for use in list_for_each_entry_continue()
354 * @pos: the type * to use as a start point
355 * @head: the head of the list
356 * @member: the name of the list_struct within the struct.
358 * Prepares a pos entry for use as a start point in list_for_each_entry_continue().
360 #define list_prepare_entry(pos, head, member) \
361 ((pos) ? : list_entry(head, typeof(*pos), member))
364 * list_for_each_entry_continue - continue iteration over list of given type
365 * @pos: the type * to use as a loop cursor.
366 * @head: the head for your list.
367 * @member: the name of the list_struct within the struct.
369 * Continue to iterate over list of given type, continuing after
370 * the current position.
372 #define list_for_each_entry_continue(pos, head, member) \
373 for (pos = list_entry(pos->member.next, typeof(*pos), member); \
374 &pos->member != (head); \
375 pos = list_entry(pos->member.next, typeof(*pos), member))
378 * list_for_each_entry_continue_reverse - iterate backwards from the given point
379 * @pos: the type * to use as a loop cursor.
380 * @head: the head for your list.
381 * @member: the name of the list_struct within the struct.
383 * Start to iterate over list of given type backwards, continuing after
384 * the current position.
386 #define list_for_each_entry_continue_reverse(pos, head, member) \
387 for (pos = list_entry(pos->member.prev, typeof(*pos), member); \
388 &pos->member != (head); \
389 pos = list_entry(pos->member.prev, typeof(*pos), member))
392 * list_for_each_entry_from - iterate over list of given type from the current point
393 * @pos: the type * to use as a loop cursor.
394 * @head: the head for your list.
395 * @member: the name of the list_struct within the struct.
397 * Iterate over list of given type, continuing from current position.
399 #define list_for_each_entry_from(pos, head, member) \
400 for (; &pos->member != (head); \
401 pos = list_entry(pos->member.next, typeof(*pos), member))
404 * list_for_each_entry_safe - iterate over list of given type safe against removal of list entry
405 * @pos: the type * to use as a loop cursor.
406 * @n: another type * to use as temporary storage
407 * @head: the head for your list.
408 * @member: the name of the list_struct within the struct.
410 #define list_for_each_entry_safe(pos, n, head, member) \
411 for (pos = list_entry((head)->next, typeof(*pos), member), \
412 n = list_entry(pos->member.next, typeof(*pos), member); \
413 &pos->member != (head); \
414 pos = n, n = list_entry(n->member.next, typeof(*n), member))
417 * list_for_each_entry_safe_continue
418 * @pos: the type * to use as a loop cursor.
419 * @n: another type * to use as temporary storage
420 * @head: the head for your list.
421 * @member: the name of the list_struct within the struct.
423 * Iterate over list of given type, continuing after current point,
424 * safe against removal of list entry.
426 #define list_for_each_entry_safe_continue(pos, n, head, member) \
427 for (pos = list_entry(pos->member.next, typeof(*pos), member), \
428 n = list_entry(pos->member.next, typeof(*pos), member); \
429 &pos->member != (head); \
430 pos = n, n = list_entry(n->member.next, typeof(*n), member))
433 * list_for_each_entry_safe_from
434 * @pos: the type * to use as a loop cursor.
435 * @n: another type * to use as temporary storage
436 * @head: the head for your list.
437 * @member: the name of the list_struct within the struct.
439 * Iterate over list of given type from current point, safe against
440 * removal of list entry.
442 #define list_for_each_entry_safe_from(pos, n, head, member) \
443 for (n = list_entry(pos->member.next, typeof(*pos), member); \
444 &pos->member != (head); \
445 pos = n, n = list_entry(n->member.next, typeof(*n), member))
448 * list_for_each_entry_safe_reverse
449 * @pos: the type * to use as a loop cursor.
450 * @n: another type * to use as temporary storage
451 * @head: the head for your list.
452 * @member: the name of the list_struct within the struct.
454 * Iterate backwards over list of given type, safe against removal
455 * of list entry.
457 #define list_for_each_entry_safe_reverse(pos, n, head, member) \
458 for (pos = list_entry((head)->prev, typeof(*pos), member), \
459 n = list_entry(pos->member.prev, typeof(*pos), member); \
460 &pos->member != (head); \
461 pos = n, n = list_entry(n->member.prev, typeof(*n), member))
464 #endif