Changeset feeac0d in mainline for kernel/generic/include/adt/list.h


Ignore:
Timestamp:
2013-09-10T16:32:35Z (11 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
4982d87
Parents:
e8d6ce2
Message:

Simplify use of list_foreach.

File:
1 edited

Legend:

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

    re8d6ce2 rfeeac0d  
    6767        ((type *) (((void *)(link)) - list_link_to_void(&(((type *) NULL)->member))))
    6868
    69 #define list_foreach(list, iterator) \
    70         for (link_t *iterator = (list).head.next; \
    71             iterator != &(list).head; iterator = iterator->next)
     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)
    7274
    7375#define assert_link_not_used(link) \
     
    184186 * @return Head item of the list.
    185187 * @return NULL if the list is empty.
    186  *
    187188 */
    188189static inline link_t *list_first(const list_t *list)
     
    197198 * @return Head item of the list.
    198199 * @return NULL if the list is empty.
    199  *
    200200 */
    201201static inline link_t *list_last(list_t *list)
    202202{
    203203        return ((list->head.prev == &list->head) ? NULL : list->head.prev);
     204}
     205
     206/** Get next item in list.
     207 *
     208 * @param link Current item link
     209 * @param list List containing @a link
     210 *
     211 * @return Next item or NULL if @a link is the last item.
     212 */
     213static inline link_t *list_next(link_t *link, const list_t *list)
     214{
     215        return (link->next == &list->head) ? NULL : link->next;
     216}
     217
     218/** Get previous item in list.
     219 *
     220 * @param link Current item link
     221 * @param list List containing @a link
     222 *
     223 * @return Previous item or NULL if @a link is the first item.
     224 */
     225static inline link_t *list_prev(link_t *link, const list_t *list)
     226{
     227        return (link->prev == &list->head) ? NULL : link->prev;
    204228}
    205229
     
    270294{
    271295        unsigned int cnt = 0;
    272        
    273         list_foreach(*list, link) {
     296        link_t *link;
     297       
     298        link = list_first(list);
     299        while (link != NULL) {
    274300                if (cnt == n)
    275301                        return link;
    276302               
    277303                cnt++;
     304                link = list_next(link, list);
    278305        }
    279306       
Note: See TracChangeset for help on using the changeset viewer.