Changeset 00b7fc8 in mainline


Ignore:
Timestamp:
2019-02-01T22:32:38Z (6 years ago)
Author:
Jiří Zárevúcky <zarevucky.jiri@…>
Parents:
f959a20f
git-author:
Jiří Zárevúcky <zarevucky.jiri@…> (2019-02-01 21:46:05)
git-committer:
Jiří Zárevúcky <zarevucky.jiri@…> (2019-02-01 22:32:38)
Message:

wip

Location:
uspace
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/taskdump/fibrildump.c

    rf959a20f r00b7fc8  
    107107                        return EIO;
    108108
    109                 addr = (uintptr_t) link.next;
     109                addr = (uintptr_t) link.__adt_link_next;
    110110                if (addr == fibril_list_addr)
    111111                        break;
  • uspace/lib/c/generic/adt/list.c

    rf959a20f r00b7fc8  
    5555bool list_member(const link_t *link, const list_t *list)
    5656{
    57         bool found = false;
    58         link_t *hlp = list->head.next;
     57        if (list_empty(list))
     58                return false;
    5959
    60         while (hlp != &list->head) {
    61                 if (hlp == link) {
    62                         found = true;
    63                         break;
    64                 }
    65                 hlp = hlp->next;
     60        link_t *hlp = list->__adt_list_head.__adt_link_next;
     61
     62        while (hlp != &list->__adt_list_head) {
     63                if (hlp == link)
     64                        return true;
     65                hlp = hlp->__adt_link_next;
    6666        }
    6767
    68         return found;
     68        return false;
    6969}
    7070
     
    8383
    8484        /* Attach list to destination. */
    85         list->head.next->prev = pos;
    86         list->head.prev->next = pos->next;
     85        list->__adt_list_head.__adt_link_next->__adt_link_prev = pos;
     86        list->__adt_list_head.__adt_link_prev->__adt_link_next = pos->__adt_link_next;
    8787
    8888        /* Link destination list to the added list. */
    89         pos->next->prev = list->head.prev;
    90         pos->next = list->head.next;
     89        pos->__adt_link_next->__adt_link_prev = list->__adt_list_head.__adt_link_prev;
     90        pos->__adt_link_next = list->__adt_list_head.__adt_link_next;
    9191
    9292        list_initialize(list);
  • uspace/lib/c/include/adt/list.h

    rf959a20f r00b7fc8  
    4444
    4545/** Doubly linked list link. */
    46 typedef struct link {
    47         struct link *prev;  /**< Pointer to the previous item in the list. */
    48         struct link *next;  /**< Pointer to the next item in the list. */
     46typedef struct __adt_link {
     47        struct __adt_link *__adt_link_prev;  /**< Pointer to the previous item in the list. */
     48        struct __adt_link *__adt_link_next;  /**< Pointer to the next item in the list. */
    4949} link_t;
    5050
    5151/** Doubly linked list. */
    52 typedef struct list {
    53         link_t head;  /**< List head. Does not have any data. */
     52typedef struct {
     53        link_t __adt_list_head;  /**< List head. Does not have any data. */
    5454} list_t;
    5555
     
    8383#define LIST_INITIALIZER(name) \
    8484        { \
    85                 .head = { \
    86                         .prev = &(name).head, \
    87                         .next = &(name).head \
     85                .__adt_list_head = { \
     86                        .__adt_link_prev = &(name).__adt_list_head, \
     87                        .__adt_link_next = &(name).__adt_list_head \
    8888                } \
    8989        }
     
    9292        ((type *) (((void *)(link)) - list_link_to_void(&(((type *) NULL)->member))))
    9393
     94#define list_foreach_internal(list, member, itype, iterator, next, link) \
     95        for (itype *iterator = NULL; iterator == NULL; iterator = (itype *) 1) \
     96                for (link_t *link = (list).__adt_list_head.next; \
     97                    iterator = list_get_instance(link, itype, member), \
     98                    link != &(list).__adt_list_head; link = link->next)
     99
     100#define __ADT_LIST_CONCAT(a, b) __ADT_LIST_CONCAT1(a, b)
     101#define __ADT_LIST_CONCAT1(a, b) a##b
     102
    94103#define list_foreach(list, member, itype, iterator) \
    95         for (itype *iterator = NULL; iterator == NULL; iterator = (itype *) 1) \
    96                 for (link_t *_link = (list).head.next; \
    97                     iterator = list_get_instance(_link, itype, member), \
    98                     _link != &(list).head; _link = _link->next)
     104        list_foreach_internal(list, member, itype, iterator, __adt_link_next, __ADT_LIST_CONCAT(__tmp_link_, __COUNTER__))
    99105
    100106#define list_foreach_rev(list, member, itype, iterator) \
    101         for (itype *iterator = NULL; iterator == NULL; iterator = (itype *) 1) \
    102                 for (link_t *_link = (list).head.prev; \
    103                     iterator = list_get_instance(_link, itype, member), \
    104                     _link != &(list).head; _link = _link->prev)
     107        list_foreach_internal(list, member, itype, iterator, __adt_link_prev, __ADT_LIST_CONCAT(__tmp_link_, __COUNTER__))
    105108
    106109/** Unlike list_foreach(), allows removing items while traversing a list.
     
    130133 */
    131134#define list_foreach_safe(list, iterator, next_iter) \
    132         for (link_t *iterator = (list).head.next, \
    133             *next_iter = iterator->next; \
    134             iterator != &(list).head; \
    135             iterator = next_iter, next_iter = iterator->next)
     135        for (link_t *iterator = (list).__adt_list_head.__adt_link_next, \
     136            *next_iter = iterator->__adt_link_next; \
     137            iterator != &(list).__adt_list_head; \
     138            iterator = next_iter, next_iter = iterator->__adt_link_next)
    136139
    137140#define assert_link_not_used(link) \
     
    141144static inline bool link_in_use(const link_t *link)
    142145{
    143         return link->prev != NULL && link->next != NULL;
     146        return link->__adt_link_prev != NULL && link->__adt_link_next != NULL;
    144147}
    145148
     
    153156NO_TRACE static inline void link_initialize(link_t *link)
    154157{
    155         link->prev = NULL;
    156         link->next = NULL;
     158        assert(link);
     159        link->__adt_link_prev = NULL;
     160        link->__adt_link_next = NULL;
    157161}
    158162
     
    166170NO_TRACE static inline void list_initialize(list_t *list)
    167171{
    168         list->head.prev = &list->head;
    169         list->head.next = &list->head;
     172        assert(list);
     173        list->__adt_list_head.__adt_link_prev = &list->__adt_list_head;
     174        list->__adt_list_head.__adt_link_next = &list->__adt_list_head;
    170175}
    171176
     
    175180static inline void list_insert_before(link_t *lnew, link_t *lold)
    176181{
    177         lnew->next = lold;
    178         lnew->prev = lold->prev;
    179         lold->prev->next = lnew;
    180         lold->prev = lnew;
     182        assert(lnew);
     183        assert(lold);
     184        lnew->__adt_link_next = lold;
     185        lnew->__adt_link_prev = lold->__adt_link_prev;
     186        lold->__adt_link_prev->__adt_link_next = lnew;
     187        lold->__adt_link_prev = lnew;
    181188}
    182189
     
    186193static inline void list_insert_after(link_t *lnew, link_t *lold)
    187194{
    188         lnew->prev = lold;
    189         lnew->next = lold->next;
    190         lold->next->prev = lnew;
    191         lold->next = lnew;
     195        assert(lnew);
     196        assert(lold);
     197        lnew->__adt_link_prev = lold;
     198        lnew->__adt_link_next = lold->__adt_link_next;
     199        lold->__adt_link_next->__adt_link_prev = lnew;
     200        lold->__adt_link_next = lnew;
    192201}
    193202
     
    202211NO_TRACE static inline void list_prepend(link_t *link, list_t *list)
    203212{
    204         list_insert_after(link, &list->head);
     213        list_insert_after(link, &list->__adt_list_head);
    205214}
    206215
     
    215224NO_TRACE static inline void list_append(link_t *link, list_t *list)
    216225{
    217         list_insert_before(link, &list->head);
     226        list_insert_before(link, &list->__adt_list_head);
    218227}
    219228
     
    228237NO_TRACE static inline void list_remove(link_t *link)
    229238{
    230         if ((link->prev != NULL) && (link->next != NULL)) {
    231                 link->next->prev = link->prev;
    232                 link->prev->next = link->next;
     239        if ((link->__adt_link_prev != NULL) && (link->__adt_link_next != NULL)) {
     240                link->__adt_link_next->__adt_link_prev = link->__adt_link_prev;
     241                link->__adt_link_prev->__adt_link_next = link->__adt_link_next;
    233242        }
    234243
     
    245254NO_TRACE static inline bool list_empty(const list_t *list)
    246255{
    247         return (list->head.next == &list->head);
     256        return (list->__adt_list_head.__adt_link_next == &list->__adt_list_head);
    248257}
    249258
     
    258267static inline link_t *list_first(const list_t *list)
    259268{
    260         return ((list->head.next == &list->head) ? NULL : list->head.next);
     269        return ((list->__adt_list_head.__adt_link_next == &list->__adt_list_head) ? NULL : list->__adt_list_head.__adt_link_next);
    261270}
    262271
     
    271280static inline link_t *list_last(const list_t *list)
    272281{
    273         return (list->head.prev == &list->head) ? NULL : list->head.prev;
     282        return (list->__adt_list_head.__adt_link_prev == &list->__adt_list_head) ? NULL : list->__adt_list_head.__adt_link_prev;
    274283}
    275284
     
    283292static inline link_t *list_next(const link_t *link, const list_t *list)
    284293{
    285         return (link->next == &list->head) ? NULL : link->next;
     294        return (link->__adt_link_next == &list->__adt_list_head) ? NULL : link->__adt_link_next;
    286295}
    287296
     
    295304static inline link_t *list_prev(const link_t *link, const list_t *list)
    296305{
    297         return (link->prev == &list->head) ? NULL : link->prev;
     306        return (link->__adt_link_prev == &list->__adt_list_head) ? NULL : link->__adt_link_prev;
    298307}
    299308
     
    313322NO_TRACE static inline void headless_list_split_or_concat(link_t *part1, link_t *part2)
    314323{
    315         part1->prev->next = part2;
    316         part2->prev->next = part1;
    317 
    318         link_t *hlp = part1->prev;
    319 
    320         part1->prev = part2->prev;
    321         part2->prev = hlp;
     324        part1->__adt_link_prev->__adt_link_next = part2;
     325        part2->__adt_link_prev->__adt_link_next = part1;
     326
     327        link_t *hlp = part1->__adt_link_prev;
     328
     329        part1->__adt_link_prev = part2->__adt_link_prev;
     330        part2->__adt_link_prev = hlp;
    322331}
    323332
     
    364373NO_TRACE static inline void list_concat(list_t *list1, list_t *list2)
    365374{
    366         list_splice(list2, list1->head.prev);
     375        list_splice(list2, list1->__adt_list_head.__adt_link_prev);
    367376}
    368377
     
    408417static inline bool link_used(link_t *link)
    409418{
    410         if (link->prev == NULL && link->next == NULL)
     419        if (link->__adt_link_prev == NULL && link->__adt_link_next == NULL)
    411420                return false;
    412421
    413         assert(link->prev != NULL && link->next != NULL);
     422        assert(link->__adt_link_prev != NULL && link->__adt_link_next != NULL);
    414423        return true;
    415424}
Note: See TracChangeset for help on using the changeset viewer.