1#ifndef _LIST_H
2#define _LIST_H
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18struct list_head {
19 struct list_head *next, *prev;
20};
21
22#define LIST_HEAD_INIT(name) { &(name), &(name) }
23
24#define LIST_HEAD(name) \
25 struct list_head name = LIST_HEAD_INIT(name)
26
27static inline void INIT_LIST_HEAD(struct list_head *list)
28{
29 list->next = list;
30 list->prev = list;
31}
32
33
34
35
36
37
38
39static inline void __list_add(struct list_head *new,
40 struct list_head *prev,
41 struct list_head *next)
42{
43 next->prev = new;
44 new->next = next;
45 new->prev = prev;
46 prev->next = new;
47}
48
49
50
51
52
53
54
55
56
57static inline void list_add(struct list_head *new, struct list_head *head)
58{
59 __list_add(new, head, head->next);
60}
61
62
63
64
65
66
67
68
69static inline void __list_del(struct list_head * prev, struct list_head * next)
70{
71 next->prev = prev;
72 prev->next = next;
73}
74
75#define POISON_POINTER_DELTA 0
76#define LIST_POISON1 ((void *) 0x00100100 + POISON_POINTER_DELTA)
77#define LIST_POISON2 ((void *) 0x00200200 + POISON_POINTER_DELTA)
78
79
80
81
82
83
84
85static inline void __list_del_entry(struct list_head *entry)
86{
87 __list_del(entry->prev, entry->next);
88}
89
90static inline void list_del(struct list_head *entry)
91{
92 __list_del(entry->prev, entry->next);
93 entry->next = LIST_POISON1;
94 entry->prev = LIST_POISON2;
95}
96
97
98
99
100
101
102
103#define list_entry(ptr, type, member) \
104 container_of(ptr, type, member)
105
106
107
108
109
110#define list_for_each(pos, head) \
111 for (pos = (head)->next; pos != (head); pos = pos->next)
112
113
114
115
116
117
118
119#define list_for_each_safe(pos, n, head) \
120 for (pos = (head)->next, n = pos->next; pos != (head); \
121 pos = n, n = pos->next)
122
123#define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
124
125
126
127
128
129
130
131
132#define container_of(ptr, type, member) ({ \
133 const typeof( ((type *)0)->member ) *__mptr = (ptr); \
134 (type *)( (char *)__mptr - offsetof(type,member) );})
135
136#endif
137