Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • kernel/generic/include/adt/list.h

    r9d58539 rc14762e  
    5151} list_t;
    5252
     53
     54extern int list_member(const link_t *, const list_t *);
     55extern void list_splice(list_t *, link_t *);
     56extern unsigned int list_count(const list_t *);
     57
     58
    5359/** Declare and initialize statically allocated list.
    5460 *
     
    7177            iterator != &(list).head; iterator = iterator->next)
    7278
     79/** Unlike list_foreach(), allows removing items while traversing a list.
     80 *
     81 * @code
     82 * list_t mylist;
     83 * typedef struct item {
     84 *     int value;
     85 *     link_t item_link;
     86 * } item_t;
     87 *
     88 * //..
     89 *
     90 * // Print each list element's value and remove the element from the list.
     91 * list_foreach_safe(mylist, cur_link, next_link) {
     92 *     item_t *cur_item = list_get_instance(cur_link, item_t, item_link);
     93 *     printf("%d\n", cur_item->value);
     94 *     list_remove(cur_link);
     95 * }
     96 * @endcode
     97 *
     98 * @param list List to traverse.
     99 * @param iterator Iterator to the current element of the list.
     100 *             The item this iterator points may be safely removed
     101 *             from the list.
     102 * @param next_iter Iterator to the next element of the list.
     103 */
     104#define list_foreach_safe(list, iterator, next_iter) \
     105        for (link_t *iterator = (list).head.next, \
     106                *next_iter = iterator->next; \
     107                iterator != &(list).head; \
     108                iterator = next_iter, next_iter = iterator->next)
     109
     110       
    73111#define assert_link_not_used(link) \
    74112        ASSERT(((link)->prev == NULL) && ((link)->next == NULL))
     
    85123        link->prev = NULL;
    86124        link->next = NULL;
     125}
     126
     127/** Returns true if the initialized link is already in use by any list.
     128 *
     129 * @param link Link to examine whether if belongs to a list or not.
     130 * @return 1 if the link is part of a list.
     131 * @return 0 otherwise.
     132 */
     133NO_TRACE static inline int link_used(const link_t *link)
     134{
     135        return link->prev != NULL || link->next != NULL;
    87136}
    88137
     
    256305{
    257306        headless_list_split_or_concat(part1, part2);
     307}
     308
     309/** Concatenate two lists
     310 *
     311 * Concatenate lists @a list1 and @a list2, producing a single
     312 * list @a list1 containing items from both (in @a list1, @a list2
     313 * order) and empty list @a list2.
     314 *
     315 * @param list1         First list and concatenated output
     316 * @param list2         Second list and empty output.
     317 *
     318 */
     319NO_TRACE static inline void list_concat(list_t *list1, list_t *list2)
     320{
     321        list_splice(list2, list1->head.prev);
    258322}
    259323
     
    281345}
    282346
    283 extern int list_member(const link_t *, const list_t *);
    284 extern void list_concat(list_t *, list_t *);
    285 extern unsigned int list_count(const list_t *);
    286 
    287347#endif
    288348
Note: See TracChangeset for help on using the changeset viewer.