Ignore:
File:
1 edited

Legend:

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

    rb76ce3f re98f1c3e  
    3737#define KERN_LIST_H_
    3838
    39 #include <assert.h>
    40 #include <stdbool.h>
    41 #include <stddef.h>
     39#include <debug.h>
     40#include <typedefs.h>
    4241#include <trace.h>
    4342
     
    5352} list_t;
    5453
     54
    5555extern bool list_member(const link_t *, const list_t *);
    5656extern void list_splice(list_t *, link_t *);
    5757extern unsigned long list_count(const list_t *);
    5858
     59
    5960/** Declare and initialize statically allocated list.
    6061 *
     
    6364 */
    6465#define LIST_INITIALIZE(name) \
    65         list_t name = LIST_INITIALIZER(name)
    66 
    67 /** Initializer for statically allocated list.
    68  *
    69  * @code
    70  * struct named_list {
    71  *     const char *name;
    72  *     list_t list;
    73  * } var = {
    74  *     .name = "default name",
    75  *     .list = LIST_INITIALIZER(name_list.list)
    76  * };
    77  * @endcode
    78  *
    79  * @param name Name of the new statically allocated list.
    80  *
    81  */
    82 #define LIST_INITIALIZER(name) \
    83         { \
     66        list_t name = { \
    8467                .head = { \
    8568                        .prev = &(name).head, \
     
    10487
    10588/** Unlike list_foreach(), allows removing items while traversing a list.
    106  *
     89 * 
    10790 * @code
    10891 * list_t mylist;
     
    134117            iterator = next_iter, next_iter = iterator->next)
    135118
     119       
    136120#define assert_link_not_used(link) \
    137         assert(!link_used(link))
    138 
    139 /** Returns true if the link is definitely part of a list. False if not sure. */
    140 static inline bool link_in_use(const link_t *link)
    141 {
    142         return link->prev != NULL && link->next != NULL;
    143 }
     121        ASSERT(!link_used(link))
    144122
    145123/** Initialize doubly-linked circular list link
     
    268246 *
    269247 */
    270 static inline link_t *list_last(const list_t *list)
    271 {
    272         return (list->head.prev == &list->head) ? NULL : list->head.prev;
     248static inline link_t *list_last(list_t *list)
     249{
     250        return ((list->head.prev == &list->head) ? NULL : list->head.prev);
    273251}
    274252
     
    280258 * @return Next item or NULL if @a link is the last item.
    281259 */
    282 static inline link_t *list_next(const link_t *link, const list_t *list)
     260static inline link_t *list_next(link_t *link, const list_t *list)
    283261{
    284262        return (link->next == &list->head) ? NULL : link->next;
     
    292270 * @return Previous item or NULL if @a link is the first item.
    293271 */
    294 static inline link_t *list_prev(const link_t *link, const list_t *list)
     272static inline link_t *list_prev(link_t *link, const list_t *list)
    295273{
    296274        return (link->prev == &list->head) ? NULL : link->prev;
     
    375353 *
    376354 */
    377 static inline link_t *list_nth(const list_t *list, unsigned long n)
     355static inline link_t *list_nth(list_t *list, unsigned long n)
    378356{
    379357        unsigned long cnt = 0;
    380        
    381         link_t *link = list_first(list);
     358        link_t *link;
     359       
     360        link = list_first(list);
    382361        while (link != NULL) {
    383362                if (cnt == n)
     
    410389                return false;
    411390
    412         assert(link->prev != NULL && link->next != NULL);
     391        ASSERT(link->prev != NULL && link->next != NULL);
    413392        return true;
    414393}
Note: See TracChangeset for help on using the changeset viewer.