Changes in kernel/generic/include/adt/list.h [9d58539:7856d09] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/generic/include/adt/list.h
r9d58539 r7856d09 1 1 /* 2 2 * Copyright (c) 2001-2004 Jakub Jermar 3 * Copyright (c) 201 1Jiri Svoboda3 * Copyright (c) 2013 Jiri Svoboda 4 4 * All rights reserved. 5 5 * … … 37 37 #define KERN_LIST_H_ 38 38 39 #include <debug.h> 39 40 #include <typedefs.h> 40 41 #include <trace.h> … … 65 66 66 67 #define list_get_instance(link, type, member) \ 67 ((type *) (((void *)(link)) - ((void *) &(((type *) NULL)->member)))) 68 69 #define list_foreach(list, iterator) \ 70 for (link_t *iterator = (list).head.next; \ 71 iterator != &(list).head; iterator = iterator->next) 68 ((type *) (((void *)(link)) - list_link_to_void(&(((type *) NULL)->member)))) 69 70 #define list_foreach(list, member, itype, iterator) \ 71 for (itype *iterator = NULL; iterator == NULL; iterator = (itype *) 1) \ 72 for (link_t *_link = (list).head.next; \ 73 iterator = list_get_instance(_link, itype, member), \ 74 _link != &(list).head; _link = _link->next) 75 76 #define list_foreach_rev(list, member, itype, iterator) \ 77 for (itype *iterator = NULL; iterator == NULL; iterator = (itype *) 1) \ 78 for (link_t *_link = (list).head.prev; \ 79 iterator = list_get_instance(_link, itype, member), \ 80 _link != &(list).head; _link = _link->prev) 72 81 73 82 #define assert_link_not_used(link) \ 74 ASSERT( ((link)->prev == NULL) && ((link)->next == NULL))83 ASSERT(!link_used(link)) 75 84 76 85 /** Initialize doubly-linked circular list link … … 204 213 } 205 214 215 /** Get next item in list. 216 * 217 * @param link Current item link 218 * @param list List containing @a link 219 * 220 * @return Next item or NULL if @a link is the last item. 221 */ 222 static inline link_t *list_next(link_t *link, const list_t *list) 223 { 224 return (link->next == &list->head) ? NULL : link->next; 225 } 226 227 /** Get previous item in list. 228 * 229 * @param link Current item link 230 * @param list List containing @a link 231 * 232 * @return Previous item or NULL if @a link is the first item. 233 */ 234 static inline link_t *list_prev(link_t *link, const list_t *list) 235 { 236 return (link->prev == &list->head) ? NULL : link->prev; 237 } 238 206 239 /** Split or concatenate headless doubly-linked circular list 207 240 * … … 270 303 { 271 304 unsigned int cnt = 0; 272 273 list_foreach(*list, link) { 305 link_t *link; 306 307 link = list_first(list); 308 while (link != NULL) { 274 309 if (cnt == n) 275 310 return link; 276 311 277 312 cnt++; 313 link = list_next(link, list); 278 314 } 279 315 280 316 return NULL; 317 } 318 319 /** Verify that argument type is a pointer to link_t (at compile time). 320 * 321 * This can be used to check argument type in a macro. 322 */ 323 static inline const void *list_link_to_void(const link_t *link) 324 { 325 return link; 326 } 327 328 /** Determine if link is used. 329 * 330 * @param link Link 331 * @return @c true if link is used, @c false if not. 332 */ 333 static inline bool link_used(link_t *link) 334 { 335 if (link->prev == NULL && link->next == NULL) 336 return false; 337 338 ASSERT(link->prev != NULL && link->next != NULL); 339 return true; 281 340 } 282 341
Note:
See TracChangeset
for help on using the changeset viewer.