3 * List macros heavily inspired by the Linux kernel
4 * list handling. No list looping yet.
6 * Is not threadsafe, so common operations need to
7 * be protected using an external mutex.
9 #ifndef _U_DOUBLE_LIST_H_
10 #define _U_DOUBLE_LIST_H_
15 struct list_head *prev;
16 struct list_head *next;
19 static inline void list_inithead(struct list_head *item) { }
21 static inline void list_add(struct list_head *item, struct list_head *list) { }
23 static inline void list_addtail(struct list_head *item, struct list_head *list) { }
25 static inline void list_replace(struct list_head *from, struct list_head *to) { }
27 static inline void list_del(struct list_head *item) { }
29 static inline void list_delinit(struct list_head *item) { }
31 #define LIST_INITHEAD(__item) list_inithead(__item)
32 #define LIST_ADD(__item, __list) list_add(__item, __list)
33 #define LIST_ADDTAIL(__item, __list) list_addtail(__item, __list)
34 #define LIST_REPLACE(__from, __to) list_replace(__from, __to)
35 #define LIST_DEL(__item) list_del(__item)
36 #define LIST_DELINIT(__item) list_delinit(__item)
38 #define LIST_ENTRY(__type, __item, __field) \
39 ((__type *)(((char *)(__item)) - offsetof(__type, __field)))
41 #define LIST_IS_EMPTY(__list) \
42 ((__list)->next == (__list))
45 #define container_of(ptr, sample, member) \
46 (void *)((char *)(ptr) \
47 - ((char *)&(sample)->member - (char *)(sample)))
50 #define LIST_FOR_EACH_ENTRY(pos, head, member) \
55 #define LIST_FOR_EACH_ENTRY_SAFE(pos, storage, head, member) \
60 #define LIST_FOR_EACH_ENTRY_SAFE_REV(pos, storage, head, member) \
61 for (pos = container_of((head)->prev, pos, member), \
62 storage = container_of(pos->member.prev, pos, member); \
63 &pos->member != (head); \
64 pos = storage, storage = container_of(storage->member.prev, storage, member))
66 #define LIST_FOR_EACH_ENTRY_FROM(pos, start, head, member) \
67 for (pos = container_of((start), pos, member); \
68 &pos->member != (head); \
69 pos = container_of(pos->member.next, pos, member))
71 #define LIST_FOR_EACH_ENTRY_FROM_REV(pos, start, head, member) \
72 for (pos = container_of((start), pos, member); \
73 &pos->member != (head); \
74 pos = container_of(pos->member.prev, pos, member))
76 #define LIST_LENGTH(__item) 1
78 #endif /*_U_DOUBLE_LIST_H_*/