nckernel  0.1
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
list.h
Go to the documentation of this file.
1 
16 #define LIST_HEAD_INIT(list) { &(list), &(list) }
17 
21 #define LIST_HEAD(list) struct list_head list = LIST_HEAD_INIT(list)
22 
26 #define LIST_NEXT(name) ((name)->next)
27 
31 #define LIST_PREV(name) ((name)->prev)
32 
36 struct list_head {
37  struct list_head *next;
38  struct list_head *prev;
39 };
40 
47 #define list_entry(ptr, type, member) \
48  container_of(ptr, type, member)
49 
53 #define list_next_entry(ptr, type, member) \
54  (((ptr)->next == (ptr)) ? NULL : \
55  list_entry((ptr)->next, type, member))
56 
60 #define list_prev_entry(ptr, type, member) \
61  (((ptr)->prev == (ptr)) ? NULL : \
62  list_entry((ptr)->prev, type, member))
63 
67 #define list_for_each(pos, head) \
68  for (pos = (head)->next; \
69  prefetch(pos->next), pos != (head); pos = pos->next)
70 
74 #define list_for_each_prev(pos, head) \
75  for (pos = (head)->prev; \
76  prefetch(pos->prev), pos != (head); pos = pos->prev)
77 
81 #define list_for_each_safe(pos, n, head) \
82  for (pos = (head)->next, n = pos->next; \
83  pos != (head); pos = n, n = pos->next)
84 
88 #define list_for_each_prev_safe(pos, n, head) \
89  for (pos = (head)->prev, n = pos->prev; \
90  prefetch(pos->prev), pos != (head); pos = n, n = pos->prev)
91 
95 #define list_for_each_entry(pos, head, member) \
96  for (pos = list_entry((head)->next, typeof(*pos), member); \
97  prefetch(pos->member.next), &pos->member != (head); \
98  pos = list_entry(pos->member.next, typeof(*pos), member))
99 
105 static inline void INIT_LIST_HEAD(struct list_head *list)
106 {
107  list->next = list;
108  list->prev = list;
109 }
110 
114 static inline void __list_add(struct list_head *new,
115  struct list_head *prev, struct list_head *next)
116 {
117  next->prev = new;
118  new->next = next;
119  new->prev = prev;
120  prev->next = new;
121 }
122 
131 static inline void list_add(struct list_head *new, struct list_head *head)
132 {
133  __list_add(new, head, head->next);
134 }
135 
143 static inline void list_add_tail(struct list_head *new, struct list_head *head)
144 {
145  __list_add(new, head->prev, head);
146 }
147 
156 static inline void list_insert_after(struct list_head *new,
157  struct list_head *head)
158 {
159  new->next = head->next;
160  new->prev = head;
161 
162  new->next->prev = new;
163  head->next = new;
164 }
165 
174 static inline void list_insert_before(struct list_head *new,
175  struct list_head *head)
176 {
177  new->next = head;
178  new->prev = head->prev;
179 
180  new->prev->next = new;
181  head->prev = new;
182 }
183 
187 static inline void __list_del(struct list_head *prev, struct list_head *next)
188 {
189  next->prev = prev;
190  prev->next = next;
191 }
192 
199 static inline void list_del(struct list_head *entry)
200 {
201  __list_del(entry->prev, entry->next);
202  entry->next = NULL;
203  entry->prev = NULL;
204 }
205 
213 static inline void list_replace(struct list_head *new, struct list_head *old)
214 {
215  if (old->next) {
216  old->next->prev = new;
217  }
218 
219  if (old->prev) {
220  old->prev->next = new;
221  }
222 
223  new->next = old->next;
224  new->prev = old->prev;
225 }
226 
235 static inline void list_link(struct list_head *h_o_n, struct list_head *t_o_o)
236 {
237  struct list_head *h_o_o = t_o_o->next;
238  struct list_head *t_o_n = h_o_n->prev;
239 
240  t_o_o->next = h_o_n;
241  h_o_n->prev = t_o_o;
242 
243  h_o_o->prev = t_o_n;
244  t_o_n->next = h_o_o;
245 }
246