5 /* taken from linux kernel */
8 #ifdef __compiler_offsetof
9 #define offsetof(TYPE,MEMBER) __compiler_offsetof(TYPE,MEMBER)
11 #define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
14 #define list_container_of(ptr, type, member) ({ \
15 const typeof( ((type *)0)->member ) *__mptr = (ptr); \
16 (type *)( (char *)__mptr - offsetof(type,member) );})
19 struct list_head
*next
, *prev
;
22 #define LIST_HEAD_INIT(name) { &(name), &(name) }
24 #define LIST_HEAD(name) \
25 struct list_head name = LIST_HEAD_INIT(name)
27 static inline void INIT_LIST_HEAD(struct list_head
*list
)
33 static inline int list_empty(const struct list_head
*head
)
35 return head
->next
== head
;
38 #define list_entry(ptr, type, member) \
39 list_container_of(ptr, type, member)
41 #define list_for_each(pos, head) \
42 for (pos = (head)->next; pos != (head); pos = pos->next)
44 #define list_for_each_entry(pos, head, member) \
45 for (pos = list_entry((head)->next, typeof(*pos), member); \
46 &pos->member != (head); \
47 pos = list_entry(pos->member.next, typeof(*pos), member))
49 #define list_for_each_entry_safe(pos, n, head, member) \
50 for (pos = list_entry((head)->next, typeof(*pos), member), \
51 n = list_entry(pos->member.next, typeof(*pos), member); \
52 &pos->member != (head); \
53 pos = n, n = list_entry(n->member.next, typeof(*n), member))
55 static inline void __list_add(struct list_head
*new,
56 struct list_head
*prev
,
57 struct list_head
*next
)
65 static inline void list_add(struct list_head
*new, struct list_head
*head
)
67 __list_add(new, head
, head
->next
);
70 static inline void list_add_tail(struct list_head
*new, struct list_head
*head
)
72 __list_add(new, head
->prev
, head
);
75 static inline void __list_del(struct list_head
* prev
, struct list_head
* next
)
81 static inline void list_del(struct list_head
*entry
)
83 __list_del(entry
->prev
, entry
->next
);
84 entry
->next
= entry
->prev
= NULL
;
87 static inline void list_del_init(struct list_head
*entry
)
89 __list_del(entry
->prev
, entry
->next
);
90 INIT_LIST_HEAD(entry
);
94 * list_move_tail - delete from one list and add as another's tail
95 * @list: the entry to move
96 * @head: the head that will follow our entry
98 static inline void list_move_tail(struct list_head
*list
,
99 struct list_head
*head
)
101 __list_del(list
->prev
, list
->next
);
102 list_add_tail(list
, head
);