Rev 5725 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 5725 | Rev 5728 | ||
---|---|---|---|
Line 163... | Line 163... | ||
163 | return head->next == head; |
163 | return head->next == head; |
164 | } |
164 | } |
Line 165... | Line 165... | ||
165 | 165 | ||
166 | #define container_of(ptr, type, member) ({ \ |
166 | #define container_of(ptr, type, member) ({ \ |
167 | const typeof( ((type *)0)->member ) *__mptr = (ptr); \ |
167 | const typeof( ((type *)0)->member ) *__mptr = (ptr); \ |
- | 168 | (type *)( (char *)__mptr - offsetof(type,member) );}) |
|
Line 168... | Line 169... | ||
168 | (type *)( (char *)__mptr - __builtin_offsetof(type,member) );}) |
169 | |
169 | 170 | ||
170 | 171 | ||
171 | /** |
172 | /** |
172 | * list_entry - get the struct for this entry |
173 | * list_entry - get the struct for this entry |
173 | * @ptr: the &struct list_head pointer. |
174 | * @ptr: the &struct list_head pointer. |
174 | * @type: the type of the struct this is embedded in. |
175 | * @type: the type of the struct this is embedded in. |
175 | * @member: the name of the list_struct within the struct. |
176 | * @member: the name of the list_head within the struct. |
Line 176... | Line 177... | ||
176 | */ |
177 | */ |
177 | #define list_entry(ptr, type, member) \ |
178 | #define list_entry(ptr, type, member) \ |
178 | container_of(ptr, type, member) |
179 | container_of(ptr, type, member) |
179 | 180 | ||
180 | /** |
181 | /** |
181 | * list_first_entry - get the first element from a list |
182 | * list_first_entry - get the first element from a list |
182 | * @ptr: the list head to take the element from. |
183 | * @ptr: the list head to take the element from. |
183 | * @type: the type of the struct this is embedded in. |
184 | * @type: the type of the struct this is embedded in. |
184 | * @member: the name of the list_struct within the struct. |
185 | * @member: the name of the list_head within the struct. |
185 | * |
186 | * |
Line 186... | Line 187... | ||
186 | * Note, that list is expected to be not empty. |
187 | * Note, that list is expected to be not empty. |
- | 188 | */ |
|
- | 189 | #define list_first_entry(ptr, type, member) \ |
|
- | 190 | list_entry((ptr)->next, type, member) |
|
- | 191 | ||
- | 192 | /** |
|
- | 193 | * list_last_entry - get the last element from a list |
|
- | 194 | * @ptr: the list head to take the element from. |
|
- | 195 | * @type: the type of the struct this is embedded in. |
|
- | 196 | * @member: the name of the list_head within the struct. |
|
- | 197 | * |
|
- | 198 | * Note, that list is expected to be not empty. |
|
- | 199 | */ |
|
- | 200 | #define list_last_entry(ptr, type, member) \ |
|
- | 201 | list_entry((ptr)->prev, type, member) |
|
- | 202 | ||
- | 203 | /** |
|
- | 204 | * list_first_entry_or_null - get the first element from a list |
|
- | 205 | * @ptr: the list head to take the element from. |
|
- | 206 | * @type: the type of the struct this is embedded in. |
|
- | 207 | * @member: the name of the list_head within the struct. |
|
- | 208 | * |
|
- | 209 | * Note that if the list is empty, it returns NULL. |
|
- | 210 | */ |
|
- | 211 | #define list_first_entry_or_null(ptr, type, member) \ |
|
- | 212 | (!list_empty(ptr) ? list_first_entry(ptr, type, member) : NULL) |
|
- | 213 | ||
- | 214 | /** |
|
- | 215 | * list_next_entry - get the next element in list |
|
- | 216 | * @pos: the type * to cursor |
|
- | 217 | * @member: the name of the list_head within the struct. |
|
- | 218 | */ |
|
- | 219 | #define list_next_entry(pos, member) \ |
|
- | 220 | list_entry((pos)->member.next, typeof(*(pos)), member) |
|
- | 221 | ||
- | 222 | /** |
|
- | 223 | * list_prev_entry - get the prev element in list |
|
- | 224 | * @pos: the type * to cursor |
|
- | 225 | * @member: the name of the list_head within the struct. |
|
187 | */ |
226 | */ |
188 | #define list_first_entry(ptr, type, member) \ |
227 | #define list_prev_entry(pos, member) \ |
189 | list_entry((ptr)->next, type, member) |
228 | list_entry((pos)->member.prev, typeof(*(pos)), member) |
190 | 229 | ||
191 | /** |
230 | /** |
192 | * list_for_each - iterate over a list |
231 | * list_for_each - iterate over a list |
Line 193... | Line -... | ||
193 | * @pos: the &struct list_head to use as a loop cursor. |
- | |
194 | * @head: the head for your list. |
232 | * @pos: the &struct list_head to use as a loop cursor. |
195 | */ |
233 | * @head: the head for your list. |
196 | #define list_for_each(pos, head) \ |
234 | */ |
197 | for (pos = (head)->next; pos != (head); pos = pos->next) |
235 | #define list_for_each(pos, head) \ |
198 | 236 | for (pos = (head)->next; pos != (head); pos = pos->next) |
|
Line 228... | Line 266... | ||
228 | 266 | ||
229 | /** |
267 | /** |
230 | * list_for_each_entry - iterate over list of given type |
268 | * list_for_each_entry - iterate over list of given type |
231 | * @pos: the type * to use as a loop cursor. |
269 | * @pos: the type * to use as a loop cursor. |
232 | * @head: the head for your list. |
270 | * @head: the head for your list. |
233 | * @member: the name of the list_struct within the struct. |
271 | * @member: the name of the list_head within the struct. |
234 | */ |
272 | */ |
235 | #define list_for_each_entry(pos, head, member) \ |
273 | #define list_for_each_entry(pos, head, member) \ |
236 | for (pos = list_entry((head)->next, typeof(*pos), member); \ |
274 | for (pos = list_first_entry(head, typeof(*pos), member); \ |
237 | &pos->member != (head); \ |
275 | &pos->member != (head); \ |
Line 238... | Line 276... | ||
238 | pos = list_entry(pos->member.next, typeof(*pos), member)) |
276 | pos = list_next_entry(pos, member)) |
239 | 277 | ||
240 | /** |
278 | /** |
241 | * list_for_each_entry_reverse - iterate backwards over list of given type. |
279 | * list_for_each_entry_reverse - iterate backwards over list of given type. |
242 | * @pos: the type * to use as a loop cursor. |
280 | * @pos: the type * to use as a loop cursor. |
243 | * @head: the head for your list. |
281 | * @head: the head for your list. |
244 | * @member: the name of the list_struct within the struct. |
282 | * @member: the name of the list_head within the struct. |
245 | */ |
283 | */ |
246 | #define list_for_each_entry_reverse(pos, head, member) \ |
284 | #define list_for_each_entry_reverse(pos, head, member) \ |
247 | for (pos = list_entry((head)->prev, typeof(*pos), member); \ |
285 | for (pos = list_last_entry(head, typeof(*pos), member); \ |
Line -... | Line 286... | ||
- | 286 | &pos->member != (head); \ |
|
- | 287 | pos = list_prev_entry(pos, member)) |
|
- | 288 | ||
- | 289 | /** |
|
- | 290 | * list_prepare_entry - prepare a pos entry for use in list_for_each_entry_continue() |
|
- | 291 | * @pos: the type * to use as a start point |
|
- | 292 | * @head: the head of the list |
|
- | 293 | * @member: the name of the list_head within the struct. |
|
- | 294 | * |
|
- | 295 | * Prepares a pos entry for use as a start point in list_for_each_entry_continue(). |
|
- | 296 | */ |
|
- | 297 | #define list_prepare_entry(pos, head, member) \ |
|
- | 298 | ((pos) ? : list_entry(head, typeof(*pos), member)) |
|
- | 299 | ||
- | 300 | /** |
|
- | 301 | * list_for_each_entry_safe - iterate over list of given type safe against removal of list entry |
|
- | 302 | * @pos: the type * to use as a loop cursor. |
|
- | 303 | * @n: another type * to use as temporary storage |
|
- | 304 | * @head: the head for your list. |
|
- | 305 | * @member: the name of the list_head within the struct. |
|
- | 306 | */ |
|
- | 307 | #define list_for_each_entry_safe(pos, n, head, member) \ |
|
- | 308 | for (pos = list_first_entry(head, typeof(*pos), member), \ |
|
Line 248... | Line 309... | ||
248 | &pos->member != (head); \ |
309 | n = list_next_entry(pos, member); \ |