Changes in kernel/generic/include/adt/list.h [7856d09:9d58539] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/generic/include/adt/list.h
r7856d09 r9d58539 1 1 /* 2 2 * Copyright (c) 2001-2004 Jakub Jermar 3 * Copyright (c) 201 3Jiri Svoboda3 * Copyright (c) 2011 Jiri Svoboda 4 4 * All rights reserved. 5 5 * … … 37 37 #define KERN_LIST_H_ 38 38 39 #include <debug.h>40 39 #include <typedefs.h> 41 40 #include <trace.h> … … 66 65 67 66 #define list_get_instance(link, type, member) \ 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) 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) 81 72 82 73 #define assert_link_not_used(link) \ 83 ASSERT( !link_used(link))74 ASSERT(((link)->prev == NULL) && ((link)->next == NULL)) 84 75 85 76 /** Initialize doubly-linked circular list link … … 213 204 } 214 205 215 /** Get next item in list.216 *217 * @param link Current item link218 * @param list List containing @a link219 *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 link230 * @param list List containing @a link231 *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 239 206 /** Split or concatenate headless doubly-linked circular list 240 207 * … … 303 270 { 304 271 unsigned int cnt = 0; 305 link_t *link; 306 307 link = list_first(list); 308 while (link != NULL) { 272 273 list_foreach(*list, link) { 309 274 if (cnt == n) 310 275 return link; 311 276 312 277 cnt++; 313 link = list_next(link, list);314 278 } 315 279 316 280 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 Link331 * @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;340 281 } 341 282
Note:
See TracChangeset
for help on using the changeset viewer.