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


Ignore:
Timestamp:
2017-06-27T16:52:59Z (7 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
30eab78
Parents:
9e7615d
Message:

Reduce divergence between kernel and libc versions of adt/list.h

File:
1 edited

Legend:

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

    r9e7615d rb76ce3f  
    5353} list_t;
    5454
    55 
    5655extern bool list_member(const link_t *, const list_t *);
    5756extern void list_splice(list_t *, link_t *);
    5857extern unsigned long list_count(const list_t *);
    5958
    60 
    6159/** Declare and initialize statically allocated list.
    6260 *
     
    6563 */
    6664#define LIST_INITIALIZE(name) \
    67         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        { \
    6884                .head = { \
    6985                        .prev = &(name).head, \
     
    88104
    89105/** Unlike list_foreach(), allows removing items while traversing a list.
    90  * 
     106 *
    91107 * @code
    92108 * list_t mylist;
     
    118134            iterator = next_iter, next_iter = iterator->next)
    119135
    120        
    121136#define assert_link_not_used(link) \
    122137        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}
    123144
    124145/** Initialize doubly-linked circular list link
     
    247268 *
    248269 */
    249 static inline link_t *list_last(list_t *list)
    250 {
    251         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;
    252273}
    253274
     
    259280 * @return Next item or NULL if @a link is the last item.
    260281 */
    261 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)
    262283{
    263284        return (link->next == &list->head) ? NULL : link->next;
     
    271292 * @return Previous item or NULL if @a link is the first item.
    272293 */
    273 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)
    274295{
    275296        return (link->prev == &list->head) ? NULL : link->prev;
     
    354375 *
    355376 */
    356 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)
    357378{
    358379        unsigned long cnt = 0;
    359         link_t *link;
    360380       
    361         link = list_first(list);
     381        link_t *link = list_first(list);
    362382        while (link != NULL) {
    363383                if (cnt == n)
Note: See TracChangeset for help on using the changeset viewer.