Changes in kernel/generic/include/adt/list.h [e98f1c3e:7856d09] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/generic/include/adt/list.h
re98f1c3e r7856d09 52 52 } list_t; 53 53 54 55 extern bool list_member(const link_t *, const list_t *);56 extern void list_splice(list_t *, link_t *);57 extern unsigned long list_count(const list_t *);58 59 60 54 /** Declare and initialize statically allocated list. 61 55 * … … 76 70 #define list_foreach(list, member, itype, iterator) \ 77 71 for (itype *iterator = NULL; iterator == NULL; iterator = (itype *) 1) \ 78 79 80 72 for (link_t *_link = (list).head.next; \ 73 iterator = list_get_instance(_link, itype, member), \ 74 _link != &(list).head; _link = _link->next) 81 75 82 76 #define list_foreach_rev(list, member, itype, iterator) \ 83 77 for (itype *iterator = NULL; iterator == NULL; iterator = (itype *) 1) \ 84 for (link_t *_link = (list).head.prev; \ 85 iterator = list_get_instance(_link, itype, member), \ 86 _link != &(list).head; _link = _link->prev) 87 88 /** Unlike list_foreach(), allows removing items while traversing a list. 89 * 90 * @code 91 * list_t mylist; 92 * typedef struct item { 93 * int value; 94 * link_t item_link; 95 * } item_t; 96 * 97 * //.. 98 * 99 * // Print each list element's value and remove the element from the list. 100 * list_foreach_safe(mylist, cur_link, next_link) { 101 * item_t *cur_item = list_get_instance(cur_link, item_t, item_link); 102 * printf("%d\n", cur_item->value); 103 * list_remove(cur_link); 104 * } 105 * @endcode 106 * 107 * @param list List to traverse. 108 * @param iterator Iterator to the current element of the list. 109 * The item this iterator points may be safely removed 110 * from the list. 111 * @param next_iter Iterator to the next element of the list. 112 */ 113 #define list_foreach_safe(list, iterator, next_iter) \ 114 for (link_t *iterator = (list).head.next, \ 115 *next_iter = iterator->next; \ 116 iterator != &(list).head; \ 117 iterator = next_iter, next_iter = iterator->next) 118 119 78 for (link_t *_link = (list).head.prev; \ 79 iterator = list_get_instance(_link, itype, member), \ 80 _link != &(list).head; _link = _link->prev) 81 120 82 #define assert_link_not_used(link) \ 121 83 ASSERT(!link_used(link)) … … 220 182 * 221 183 */ 222 NO_TRACE static inline boollist_empty(const list_t *list)184 NO_TRACE static inline int list_empty(const list_t *list) 223 185 { 224 186 return (list->head.next == &list->head); … … 329 291 } 330 292 331 /** Concatenate two lists332 *333 * Concatenate lists @a list1 and @a list2, producing a single334 * list @a list1 containing items from both (in @a list1, @a list2335 * order) and empty list @a list2.336 *337 * @param list1 First list and concatenated output338 * @param list2 Second list and empty output.339 *340 */341 NO_TRACE static inline void list_concat(list_t *list1, list_t *list2)342 {343 list_splice(list2, list1->head.prev);344 }345 346 293 /** Get n-th item in a list. 347 294 * … … 353 300 * 354 301 */ 355 static inline link_t *list_nth(list_t *list, unsigned longn)356 { 357 unsigned longcnt = 0;302 static inline link_t *list_nth(list_t *list, unsigned int n) 303 { 304 unsigned int cnt = 0; 358 305 link_t *link; 359 306 … … 393 340 } 394 341 342 extern int list_member(const link_t *, const list_t *); 343 extern void list_concat(list_t *, list_t *); 344 extern unsigned int list_count(const list_t *); 345 395 346 #endif 396 347
Note:
See TracChangeset
for help on using the changeset viewer.