2
* Copyright (C) 2004,2005 Heinz Mauelshagen, Red Hat GmbH.
5
* See file LICENSE at the top of this source tree for license information.
12
* Double-linked list definitons and macros.
16
struct list_head *next;
17
struct list_head *prev;
20
#define INIT_LIST_HEAD(a) do { (a)->next = (a)->prev = a; } while(0)
22
#define LIST_HEAD(a) struct list_head a = { .next = &a, .prev = &a }
24
#define list_empty(pos) ((pos)->next == pos)
26
static inline void __list_add(struct list_head *new,
27
struct list_head *prev,
28
struct list_head *next)
36
/* Add an element 'new' after position 'pos' to a list. */
37
#define list_add(new, pos) __list_add(new, pos, (pos)->next)
39
/* Add an element 'new' before position 'pos' to a list. */
40
#define list_add_tail(new, pos) __list_add(new, (pos)->prev, pos)
42
/* Delete an element 'pos' from the list. */
43
#define list_del(pos) { \
44
(pos)->next->prev = (pos)->prev; \
45
(pos)->prev->next = (pos)->next; \
46
(pos)->next = (pos)->prev = 0; \
49
#define list_del_init(pos) { \
51
INIT_LIST_HEAD(pos); \
54
/* Pointer to a struct 'type' derived from 'pos' and list_head* 'member'. */
55
#define list_entry(pos, type, member) \
56
((type*) ((char*)pos - (unsigned long)(&((type*)0)->member)))
59
#define list_for_each(pos, head) \
60
for (pos = (head)->next; pos != head; pos = pos->next)
62
/* Walk a list by entry. */
63
#define list_for_each_entry(entry, head, member) \
64
for (entry = list_entry((head)->next, typeof(*entry), member); \
65
&entry->member != (head); \
66
entry = list_entry(entry->member.next, typeof(*entry), member))
69
* Walk a list using a temporary pointer,
70
* so that elements can be deleted safely.
72
#define list_for_each_safe(pos, n, head) \
73
for (pos = (head)->next, n = pos->next; \
75
pos = n, n = pos->next)