Ignore:
File:
1 edited

Legend:

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

    r07525cd r9d58539  
    11/*
    22 * Copyright (c) 2001-2004 Jakub Jermar
    3  * Copyright (c) 2013 Jiri Svoboda
     3 * Copyright (c) 2011 Jiri Svoboda
    44 * All rights reserved.
    55 *
     
    6565
    6666#define list_get_instance(link, type, member) \
    67         ((type *) (((void *)(link)) - list_link_to_void(&(((type *) NULL)->member))))
    68 
    69 #define list_foreach(list, member, itype, iterator) \
    70         for (itype *iterator = NULL; iterator == NULL; iterator = (itype *) 1) \
    71             for (link_t *_link = (list).head.next; \
    72             iterator = list_get_instance(_link, itype, member), \
    73             _link != &(list).head; _link = _link->next)
     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)
    7472
    7573#define assert_link_not_used(link) \
     
    206204}
    207205
    208 /** Get next item in list.
    209  *
    210  * @param link Current item link
    211  * @param list List containing @a link
    212  *
    213  * @return Next item or NULL if @a link is the last item.
    214  */
    215 static inline link_t *list_next(link_t *link, const list_t *list)
    216 {
    217         return (link->next == &list->head) ? NULL : link->next;
    218 }
    219 
    220 /** Get previous item in list.
    221  *
    222  * @param link Current item link
    223  * @param list List containing @a link
    224  *
    225  * @return Previous item or NULL if @a link is the first item.
    226  */
    227 static inline link_t *list_prev(link_t *link, const list_t *list)
    228 {
    229         return (link->prev == &list->head) ? NULL : link->prev;
    230 }
    231 
    232206/** Split or concatenate headless doubly-linked circular list
    233207 *
     
    296270{
    297271        unsigned int cnt = 0;
    298         link_t *link;
    299        
    300         link = list_first(list);
    301         while (link != NULL) {
     272       
     273        list_foreach(*list, link) {
    302274                if (cnt == n)
    303275                        return link;
    304276               
    305277                cnt++;
    306                 link = list_next(link, list);
    307278        }
    308279       
    309280        return NULL;
    310 }
    311 
    312 /** Verify that argument type is a pointer to link_t (at compile time).
    313  *
    314  * This can be used to check argument type in a macro.
    315  */
    316 static inline const void *list_link_to_void(const link_t *link)
    317 {
    318         return link;
    319281}
    320282
Note: See TracChangeset for help on using the changeset viewer.