5 * Copied from include/linux/...
9 #define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
12 * container_of - cast a member of a structure out to the containing structure
13 * @ptr: the pointer to the member.
14 * @type: the type of the container struct this is embedded in.
15 * @member: the name of the member within the struct.
18 #define container_of(ptr, type, member) ({ \
19 const typeof( ((type *)0)->member ) *__mptr = (ptr); \
20 (type *)( (char *)__mptr - offsetof(type,member) );})
24 struct list_head
*next
, *prev
;
28 #define LIST_HEAD_INIT(name) { &(name), &(name) }
30 #define LIST_HEAD(name) \
31 struct list_head name = LIST_HEAD_INIT(name)
34 * list_entry - get the struct for this entry
35 * @ptr: the &struct list_head pointer.
36 * @type: the type of the struct this is embedded in.
37 * @member: the name of the list_struct within the struct.
39 #define list_entry(ptr, type, member) \
40 container_of(ptr, type, member)
43 * list_for_each_entry - iterate over list of given type
44 * @pos: the type * to use as a loop cursor.
45 * @head: the head for your list.
46 * @member: the name of the list_struct within the struct.
48 #define list_for_each_entry(pos, head, member) \
49 for (pos = list_entry((head)->next, typeof(*pos), member); \
50 &pos->member != (head); \
51 pos = list_entry(pos->member.next, typeof(*pos), member))
54 * list_empty - tests whether a list is empty
55 * @head: the list to test.
57 static inline int list_empty(const struct list_head
*head
)
59 return head
->next
== head
;
63 * Insert a new entry between two known consecutive entries.
65 * This is only for internal list manipulation where we know
66 * the prev/next entries already!
68 static inline void __list_add(struct list_head
*_new
,
69 struct list_head
*prev
,
70 struct list_head
*next
)
79 * list_add_tail - add a new entry
80 * @new: new entry to be added
81 * @head: list head to add it before
83 * Insert a new entry before the specified head.
84 * This is useful for implementing queues.
86 static inline void list_add_tail(struct list_head
*_new
, struct list_head
*head
)
88 __list_add(_new
, head
->prev
, head
);