1 #ifndef FIRM_ADT_LIST_H
2 #define FIRM_ADT_LIST_H
30 #define LIST_HEAD_INIT(name) { &(name), &(name) }
33 #define LIST_HEAD(name) \
34 struct list_head name = LIST_HEAD_INIT(name)
37 #define INIT_LIST_HEAD(ptr) do { \
38 (ptr)->next = (ptr); (ptr)->prev = (ptr); \
46 #define _list_offsetof(type,member) \
47 ((char *) &(((type *) 0)->member) - (char *) 0)
49 #define _list_container_of(ptr, type, member) \
50 ((type *) ((char *) (ptr) - _list_offsetof(type, member)))
63 next->prev = new_node;
64 new_node->next = next;
65 new_node->prev = prev;
66 prev->next = new_node;
163 return head->next == head;
220 #define list_entry(ptr, type, member) \
221 _list_container_of(ptr, type, member)
228 #define list_for_each(pos, head) \
229 for (pos = (head)->next; pos != (head); pos = pos->next)
236 #define list_for_each_prev(pos, head) \
237 for (pos = (head)->prev; pos != (head); pos = pos->prev)
245 #define list_for_each_safe(pos, n, head) \
246 for (pos = (head)->next, n = pos->next; pos != (head); \
247 pos = n, n = pos->next)
256 #define list_for_each_entry(type, pos, head, member) \
257 for (type *pos = list_entry((head)->next, type, member); \
258 &pos->member != (head); \
259 pos = list_entry(pos->member.next, type, member))
268 #define list_for_each_entry_reverse(type, pos, head, member) \
269 for (type *pos = list_entry((head)->prev, type, member); \
270 &pos->member != (head); \
271 pos = list_entry(pos->member.prev, type, member))
282 #define list_for_each_entry_safe(type, pos, n, head, member) \
283 for (type *pos = list_entry((head)->next, type, member), \
284 *n = list_entry(pos->member.next, type, member); \
285 &pos->member != (head); \
286 pos = n, n = list_entry(n->member.next, type, member))