5 #ifdef __compiler_offsetof
6 #define offsetof(TYPE,MEMBER) __compiler_offsetof(TYPE,MEMBER)
8 #define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
11 #define container_of(ptr, type, member) ({ \
12 const typeof( ((type *)0)->member ) *__mptr = (ptr); \
13 (type *)( (char *)__mptr - offsetof(type,member) );})
16 * Simple doubly linked list implementation.
18 * Some of the internal functions ("__xxx") are useful when
19 * manipulating whole lists rather than single entries, as
20 * sometimes we already know the next/prev entries and we can
21 * generate better code by using them directly rather than
22 * using the generic single-entry routines.
26 struct flist_head *next, *prev;
29 #define FLIST_HEAD_INIT(name) { &(name), &(name) }
31 #define FLIST_HEAD(name) \
32 struct flist_head name = FLIST_HEAD_INIT(name)
34 #define INIT_FLIST_HEAD(ptr) do { \
35 (ptr)->next = (ptr); (ptr)->prev = (ptr); \
39 * Insert a new entry between two known consecutive entries.
41 * This is only for internal list manipulation where we know
42 * the prev/next entries already!
44 static inline void __flist_add(struct flist_head *new_entry,
45 struct flist_head *prev,
46 struct flist_head *next)
48 next->prev = new_entry;
49 new_entry->next = next;
50 new_entry->prev = prev;
51 prev->next = new_entry;
55 * flist_add - add a new entry
56 * @new_entry: new entry to be added
57 * @head: list head to add it after
59 * Insert a new entry after the specified head.
60 * This is good for implementing stacks.
62 static inline void flist_add(struct flist_head *new_entry,
63 struct flist_head *head)
65 __flist_add(new_entry, head, head->next);
68 static inline void flist_add_tail(struct flist_head *new_entry,
69 struct flist_head *head)
71 __flist_add(new_entry, head->prev, head);
75 * Delete a list entry by making the prev/next entries
76 * point to each other.
78 * This is only for internal list manipulation where we know
79 * the prev/next entries already!
81 static inline void __flist_del(struct flist_head *prev,
82 struct flist_head * next)
89 * flist_del - deletes entry from list.
90 * @entry: the element to delete from the list.
91 * Note: flist_empty on entry does not return true after this, the entry is
92 * in an undefined state.
94 static inline void flist_del(struct flist_head *entry)
96 __flist_del(entry->prev, entry->next);
102 * flist_del_init - deletes entry from list and reinitialize it.
103 * @entry: the element to delete from the list.
105 static inline void flist_del_init(struct flist_head *entry)
107 __flist_del(entry->prev, entry->next);
108 INIT_FLIST_HEAD(entry);
112 * flist_empty - tests whether a list is empty
113 * @head: the list to test.
115 static inline int flist_empty(const struct flist_head *head)
117 return head->next == head;
121 * flist_entry - get the struct for this entry
122 * @ptr: the &struct flist_head pointer.
123 * @type: the type of the struct this is embedded in.
124 * @member: the name of the flist_struct within the struct.
126 #define flist_entry(ptr, type, member) \
127 container_of(ptr, type, member)
130 * flist_for_each - iterate over a list
131 * @pos: the &struct flist_head to use as a loop counter.
132 * @head: the head for your list.
134 #define flist_for_each(pos, head) \
135 for (pos = (head)->next; pos != (head); pos = pos->next)
138 * flist_for_each_safe - iterate over a list safe against removal of list entry
139 * @pos: the &struct flist_head to use as a loop counter.
140 * @n: another &struct flist_head to use as temporary storage
141 * @head: the head for your list.
143 #define flist_for_each_safe(pos, n, head) \
144 for (pos = (head)->next, n = pos->next; pos != (head); \
145 pos = n, n = pos->next)