17 #define DL_LIST_HEAD_INIT(l) { &(l), &(l) }
19 static inline void dl_list_init(
struct dl_list *list)
25 static inline void dl_list_add(
struct dl_list *list,
struct dl_list *item)
27 item->next = list->next;
29 list->next->prev = item;
33 static inline void dl_list_add_tail(
struct dl_list *list,
struct dl_list *item)
35 dl_list_add(list->prev, item);
38 static inline void dl_list_del(
struct dl_list *item)
40 item->next->prev = item->prev;
41 item->prev->next = item->next;
46 static inline int dl_list_empty(
struct dl_list *list)
48 return list->next == list;
51 static inline unsigned int dl_list_len(
struct dl_list *list)
55 for (item = list->next; item != list; item = item->next)
61 #define offsetof(type, member) ((long) &((type *) 0)->member)
64 #define dl_list_entry(item, type, member) \
65 ((type *) ((char *) item - offsetof(type, member)))
67 #define dl_list_first(list, type, member) \
68 (dl_list_empty((list)) ? NULL : \
69 dl_list_entry((list)->next, type, member))
71 #define dl_list_last(list, type, member) \
72 (dl_list_empty((list)) ? NULL : \
73 dl_list_entry((list)->prev, type, member))
75 #define dl_list_for_each(item, list, type, member) \
76 for (item = dl_list_entry((list)->next, type, member); \
77 &item->member != (list); \
78 item = dl_list_entry(item->member.next, type, member))
80 #define dl_list_for_each_safe(item, n, list, type, member) \
81 for (item = dl_list_entry((list)->next, type, member), \
82 n = dl_list_entry(item->member.next, type, member); \
83 &item->member != (list); \
84 item = n, n = dl_list_entry(n->member.next, type, member))
86 #define dl_list_for_each_reverse(item, list, type, member) \
87 for (item = dl_list_entry((list)->prev, type, member); \
88 &item->member != (list); \
89 item = dl_list_entry(item->member.prev, type, member))
91 #define DEFINE_DL_LIST(name) \
92 struct dl_list name = { &(name), &(name) }
Doubly-linked list.
Definition: list.h:12