1#ifndef _LINUX_LIST_H
2#define _LINUX_LIST_H
3
4#ifdef __KERNEL__
5
6
7
8
9
10
11
12
13
14
15
16struct list_head {
17 struct list_head *next, *prev;
18};
19
20#define LIST_HEAD_INIT(name) { &(name), &(name) }
21
22#define LIST_HEAD(name) \
23 struct list_head name = LIST_HEAD_INIT(name)
24
25#define INIT_LIST_HEAD(ptr) do { \
26 (ptr)->next = (ptr); (ptr)->prev = (ptr); \
27} while (0)
28
29
30
31
32
33
34
35static __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}
44
45
46
47
48
49
50
51
52
53static __inline__ void list_add(struct list_head *new, struct list_head *head)
54{
55 __list_add(new, head, head->next);
56}
57
58
59
60
61
62
63
64
65
66static __inline__ void list_add_tail(struct list_head *new, struct list_head *head)
67{
68 __list_add(new, head->prev, head);
69}
70
71
72
73
74
75
76
77
78static __inline__ void __list_del(struct list_head * prev,
79 struct list_head * next)
80{
81 next->prev = prev;
82 prev->next = next;
83}
84
85
86
87
88
89
90static __inline__ void list_del(struct list_head *entry)
91{
92 __list_del(entry->prev, entry->next);
93}
94
95
96
97
98
99static __inline__ void list_del_init(struct list_head *entry)
100{
101 __list_del(entry->prev, entry->next);
102 INIT_LIST_HEAD(entry);
103}
104
105
106
107
108
109static __inline__ int list_empty(struct list_head *head)
110{
111 return head->next == head;
112}
113
114
115
116
117
118
119static __inline__ void list_splice(struct list_head *list, struct list_head *head)
120{
121 struct list_head *first = list->next;
122
123 if (first != list) {
124 struct list_head *last = list->prev;
125 struct list_head *at = head->next;
126
127 first->prev = head;
128 head->next = first;
129
130 last->next = at;
131 at->prev = last;
132 }
133}
134
135
136
137
138
139
140
141#define list_entry(ptr, type, member) \
142 ((type *)((char *)(ptr)-(unsigned long)(&((type *)0)->member)))
143
144
145
146
147
148
149#define list_for_each(pos, head) \
150 for (pos = (head)->next; pos != (head); pos = pos->next)
151
152#endif
153
154#endif
155