Ignore:
File:
1 edited

Legend:

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

    re98f1c3e rb76ce3f  
    3737#define KERN_LIST_H_
    3838
    39 #include <debug.h>
    40 #include <typedefs.h>
     39#include <assert.h>
     40#include <stdbool.h>
     41#include <stddef.h>
    4142#include <trace.h>
    4243
     
    5253} list_t;
    5354
    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 
    6059/** Declare and initialize statically allocated list.
    6160 *
     
    6463 */
    6564#define LIST_INITIALIZE(name) \
    66         list_t 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        { \
    6784                .head = { \
    6885                        .prev = &(name).head, \
     
    87104
    88105/** Unlike list_foreach(), allows removing items while traversing a list.
    89  * 
     106 *
    90107 * @code
    91108 * list_t mylist;
     
    117134            iterator = next_iter, next_iter = iterator->next)
    118135
    119        
    120136#define assert_link_not_used(link) \
    121         ASSERT(!link_used(link))
     137        assert(!link_used(link))
     138
     139/** Returns true if the link is definitely part of a list. False if not sure. */
     140static inline bool link_in_use(const link_t *link)
     141{
     142        return link->prev != NULL && link->next != NULL;
     143}
    122144
    123145/** Initialize doubly-linked circular list link
     
    246268 *
    247269 */
    248 static inline link_t *list_last(list_t *list)
    249 {
    250         return ((list->head.prev == &list->head) ? NULL : list->head.prev);
     270static inline link_t *list_last(const list_t *list)
     271{
     272        return (list->head.prev == &list->head) ? NULL : list->head.prev;
    251273}
    252274
     
    258280 * @return Next item or NULL if @a link is the last item.
    259281 */
    260 static inline link_t *list_next(link_t *link, const list_t *list)
     282static inline link_t *list_next(const link_t *link, const list_t *list)
    261283{
    262284        return (link->next == &list->head) ? NULL : link->next;
     
    270292 * @return Previous item or NULL if @a link is the first item.
    271293 */
    272 static inline link_t *list_prev(link_t *link, const list_t *list)
     294static inline link_t *list_prev(const link_t *link, const list_t *list)
    273295{
    274296        return (link->prev == &list->head) ? NULL : link->prev;
     
    353375 *
    354376 */
    355 static inline link_t *list_nth(list_t *list, unsigned long n)
     377static inline link_t *list_nth(const list_t *list, unsigned long n)
    356378{
    357379        unsigned long cnt = 0;
    358         link_t *link;
    359380       
    360         link = list_first(list);
     381        link_t *link = list_first(list);
    361382        while (link != NULL) {
    362383                if (cnt == n)
     
    389410                return false;
    390411
    391         ASSERT(link->prev != NULL && link->next != NULL);
     412        assert(link->prev != NULL && link->next != NULL);
    392413        return true;
    393414}
Note: See TracChangeset for help on using the changeset viewer.