Changeset b72efe8 in mainline for uspace/lib


Ignore:
Timestamp:
2011-06-19T14:38:59Z (14 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
74464e8
Parents:
1d1bb0f
Message:

Separate list_t typedef from link_t (user-space part).

  • list_t represents lists
  • Use list_first(), list_last(), list_empty() where appropriate
  • Use list_foreach() where possible
  • assert_link_not_used()
  • usb_hid_report_path_free() shall not unlink the path, caller must do it
Location:
uspace/lib
Files:
24 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/block/libblock.c

    r1d1bb0f rb72efe8  
    6060static FIBRIL_MUTEX_INITIALIZE(dcl_lock);
    6161/** Device connection list head. */
    62 static LIST_INITIALIZE(dcl_head);
     62static LIST_INITIALIZE(dcl);
    6363
    6464#define CACHE_BUCKETS_LOG2  10
     
    7272        unsigned blocks_cached;   /**< Number of cached blocks. */
    7373        hash_table_t block_hash;
    74         link_t free_head;
     74        list_t free_list;
    7575        enum cache_mode mode;
    7676} cache_t;
     
    9797static devcon_t *devcon_search(devmap_handle_t devmap_handle)
    9898{
    99         link_t *cur;
    100        
    10199        fibril_mutex_lock(&dcl_lock);
    102100       
    103         for (cur = dcl_head.next; cur != &dcl_head; cur = cur->next) {
     101        list_foreach(dcl, cur) {
    104102                devcon_t *devcon = list_get_instance(cur, devcon_t, link);
    105103                if (devcon->devmap_handle == devmap_handle) {
     
    116114    size_t bsize, void *comm_area, size_t comm_size)
    117115{
    118         link_t *cur;
    119116        devcon_t *devcon;
    120117       
     
    138135       
    139136        fibril_mutex_lock(&dcl_lock);
    140         for (cur = dcl_head.next; cur != &dcl_head; cur = cur->next) {
     137        list_foreach(dcl, cur) {
    141138                devcon_t *d = list_get_instance(cur, devcon_t, link);
    142139                if (d->devmap_handle == devmap_handle) {
     
    146143                }
    147144        }
    148         list_append(&devcon->link, &dcl_head);
     145        list_append(&devcon->link, &dcl);
    149146        fibril_mutex_unlock(&dcl_lock);
    150147        return EOK;
     
    294291       
    295292        fibril_mutex_initialize(&cache->lock);
    296         list_initialize(&cache->free_head);
     293        list_initialize(&cache->free_list);
    297294        cache->lblock_size = size;
    298295        cache->block_count = blocks;
     
    335332         * bother with the cache and block locks because we are single-threaded.
    336333         */
    337         while (!list_empty(&cache->free_head)) {
    338                 block_t *b = list_get_instance(cache->free_head.next,
     334        while (!list_empty(&cache->free_list)) {
     335                block_t *b = list_get_instance(list_first(&cache->free_list),
    339336                    block_t, free_link);
    340337
     
    367364        if (cache->blocks_cached < CACHE_LO_WATERMARK)
    368365                return true;
    369         if (!list_empty(&cache->free_head))
     366        if (!list_empty(&cache->free_list))
    370367                return false;
    371368        return true;
     
    456453                        unsigned long temp_key;
    457454recycle:
    458                         if (list_empty(&cache->free_head)) {
     455                        if (list_empty(&cache->free_list)) {
    459456                                fibril_mutex_unlock(&cache->lock);
    460457                                rc = ENOMEM;
    461458                                goto out;
    462459                        }
    463                         l = cache->free_head.next;
     460                        l = list_first(&cache->free_list);
    464461                        b = list_get_instance(l, block_t, free_link);
    465462
     
    476473                                 */
    477474                                list_remove(&b->free_link);
    478                                 list_append(&b->free_link, &cache->free_head);
     475                                list_append(&b->free_link, &cache->free_list);
    479476                                fibril_mutex_unlock(&cache->lock);
    480477                                fibril_mutex_lock(&devcon->comm_area_lock);
     
    668665                        goto retry;
    669666                }
    670                 list_append(&block->free_link, &cache->free_head);
     667                list_append(&block->free_link, &cache->free_list);
    671668        }
    672669        fibril_mutex_unlock(&block->lock);
  • uspace/lib/c/generic/adt/hash_table.c

    r1d1bb0f rb72efe8  
    6161        assert(max_keys > 0);
    6262       
    63         h->entry = malloc(m * sizeof(link_t));
     63        h->entry = malloc(m * sizeof(list_t));
    6464        if (!h->entry)
    6565                return false;
    6666       
    67         memset((void *) h->entry, 0,  m * sizeof(link_t));
     67        memset((void *) h->entry, 0,  m * sizeof(list_t));
    6868       
    6969        hash_count_t i;
     
    123123        assert(chain < h->entries);
    124124       
    125         link_t *cur;
    126         for (cur = h->entry[chain].next; cur != &h->entry[chain];
    127             cur = cur->next) {
     125        list_foreach(h->entry[chain], cur) {
    128126                if (h->op->compare(key, h->max_keys, cur)) {
    129127                        /*
     
    153151        assert(keys <= h->max_keys);
    154152       
    155         link_t *cur;
    156        
    157153        if (keys == h->max_keys) {
     154                link_t *cur;
     155               
    158156                /*
    159157                 * All keys are known, hash_table_find() can be used to find the
     
    176174        hash_index_t chain;
    177175        for (chain = 0; chain < h->entries; chain++) {
    178                 for (cur = h->entry[chain].next; cur != &h->entry[chain];
     176                link_t *cur;
     177               
     178                for (cur = h->entry[chain].head.next; cur != &h->entry[chain].head;
    179179                    cur = cur->next) {
    180180                        if (h->op->compare(key, keys, cur)) {
     
    203203{
    204204        hash_index_t bucket;
    205         link_t *cur;
    206205       
    207206        for (bucket = 0; bucket < h->entries; bucket++) {
    208                 for (cur = h->entry[bucket].next; cur != &h->entry[bucket];
    209                     cur = cur->next) {
     207                list_foreach(h->entry[bucket], cur) {
    210208                        f(cur, arg);
    211209                }
  • uspace/lib/c/generic/adt/list.c

    r1d1bb0f rb72efe8  
    3030 * @{
    3131 */
    32 /** @file
     32
     33/**
     34 * @file
     35 * @brief       Functions completing doubly linked circular list implementaion.
     36 *
     37 * This file contains some of the functions implementing doubly linked circular lists.
     38 * However, this ADT is mostly implemented in @ref list.h.
    3339 */
    3440
    3541#include <adt/list.h>
    36 
     42#include <bool.h>
    3743
    3844/** Check for membership
    3945 *
    40  * Check whether link is contained in the list head.
    41  * The membership is defined as pointer equivalence.
     46 * Check whether link is contained in a list.
     47 * Membership is defined as pointer equivalence.
    4248 *
    43  * @param link Item to look for.
    44  * @param head List to look in.
     49 * @param link  Item to look for.
     50 * @param list  List to look in.
    4551 *
    4652 * @return true if link is contained in head, false otherwise.
    4753 *
    4854 */
    49 int list_member(const link_t *link, const link_t *head)
     55int list_member(const link_t *link, const list_t *list)
    5056{
    51         int found = 0;
    52         link_t *hlp = head->next;
     57        bool found = false;
     58        link_t *hlp = list->head.next;
    5359       
    54         while (hlp != head) {
     60        while (hlp != &list->head) {
    5561                if (hlp == link) {
    56                         found = 1;
     62                        found = true;
    5763                        break;
    5864                }
     
    6369}
    6470
    65 
    6671/** Concatenate two lists
    6772 *
    68  * Concatenate lists head1 and head2, producing a single
    69  * list head1 containing items from both (in head1, head2
    70  * order) and empty list head2.
     73 * Concatenate lists @a list1 and @a list2, producing a single
     74 * list @a list1 containing items from both (in @a list1, @a list2
     75 * order) and empty list @a list2.
    7176 *
    72  * @param head1 First list and concatenated output
    73  * @param head2 Second list and empty output.
     77 * @param list1         First list and concatenated output
     78 * @param list2         Second list and empty output.
    7479 *
    7580 */
    76 void list_concat(link_t *head1, link_t *head2)
     81void list_concat(list_t *list1, list_t *list2)
    7782{
    78         if (list_empty(head2))
     83        if (list_empty(list2))
    7984                return;
    80        
    81         head2->next->prev = head1->prev;
    82         head2->prev->next = head1;
    83         head1->prev->next = head2->next;
    84         head1->prev = head2->prev;
    85         list_initialize(head2);
     85
     86        list2->head.next->prev = list1->head.prev;
     87        list2->head.prev->next = &list1->head;
     88        list1->head.prev->next = list2->head.next;
     89        list1->head.prev = list2->head.prev;
     90        list_initialize(list2);
    8691}
    87 
    8892
    8993/** Count list items
     
    9195 * Return the number of items in the list.
    9296 *
    93  * @param link List to count.
    94  *
    95  * @return Number of items in the list.
    96  *
     97 * @param list          List to count.
     98 * @return              Number of items in the list.
    9799 */
    98 unsigned int list_count(const link_t *link)
     100unsigned int list_count(const list_t *list)
    99101{
    100102        unsigned int count = 0;
    101         link_t *hlp = link->next;
    102103       
    103         while (hlp != link) {
     104        list_foreach(*list, link) {
    104105                count++;
    105                 hlp = hlp->next;
    106106        }
    107107       
  • uspace/lib/c/generic/adt/prodcons.c

    r1d1bb0f rb72efe8  
    6161                fibril_condvar_wait(&pc->cv, &pc->mtx);
    6262       
    63         link_t *head = pc->list.next;
     63        link_t *head = list_first(&pc->list);
    6464        list_remove(head);
    6565       
  • uspace/lib/c/generic/async.c

    r1d1bb0f rb72efe8  
    160160       
    161161        /** Messages that should be delivered to this fibril. */
    162         link_t msg_queue;
     162        list_t msg_queue;
    163163       
    164164        /** Identification of the opening call. */
     
    361361        wd->to_event.inlist = true;
    362362       
    363         link_t *tmp = timeout_list.next;
    364         while (tmp != &timeout_list) {
     363        link_t *tmp = timeout_list.head.next;
     364        while (tmp != &timeout_list.head) {
    365365                awaiter_t *cur
    366366                    = list_get_instance(tmp, awaiter_t, to_event.link);
     
    372372        }
    373373       
    374         list_append(&wd->to_event.link, tmp);
     374        list_insert_before(&wd->to_event.link, tmp);
    375375}
    376376
     
    569569        }
    570570       
    571         msg_t *msg = list_get_instance(conn->msg_queue.next, msg_t, link);
     571        msg_t *msg = list_get_instance(list_first(&conn->msg_queue), msg_t, link);
    572572        list_remove(&msg->link);
    573573       
     
    675675        while (!list_empty(&fibril_connection->msg_queue)) {
    676676                msg_t *msg =
    677                     list_get_instance(fibril_connection->msg_queue.next, msg_t,
    678                     link);
     677                    list_get_instance(list_first(&fibril_connection->msg_queue),
     678                    msg_t, link);
    679679               
    680680                list_remove(&msg->link);
     
    806806        futex_down(&async_futex);
    807807       
    808         link_t *cur = timeout_list.next;
    809         while (cur != &timeout_list) {
     808        link_t *cur = list_first(&timeout_list);
     809        while (cur != NULL) {
    810810                awaiter_t *waiter =
    811811                    list_get_instance(cur, awaiter_t, to_event.link);
     
    813813                if (tv_gt(&waiter->to_event.expires, &tv))
    814814                        break;
    815                
    816                 cur = cur->next;
    817815               
    818816                list_remove(&waiter->to_event.link);
     
    828826                        fibril_add_ready(waiter->fid);
    829827                }
     828               
     829                cur = list_first(&timeout_list);
    830830        }
    831831       
     
    854854                suseconds_t timeout;
    855855                if (!list_empty(&timeout_list)) {
    856                         awaiter_t *waiter = list_get_instance(timeout_list.next,
    857                             awaiter_t, to_event.link);
     856                        awaiter_t *waiter = list_get_instance(
     857                            list_first(&timeout_list), awaiter_t, to_event.link);
    858858                       
    859859                        struct timeval tv;
     
    17311731                 */
    17321732                exch = (async_exch_t *)
    1733                     list_get_instance(sess->exch_list.next, async_exch_t, sess_link);
     1733                    list_get_instance(list_first(&sess->exch_list),
     1734                    async_exch_t, sess_link);
     1735               
    17341736                list_remove(&exch->sess_link);
    17351737                list_remove(&exch->global_link);
     
    17431745                        exch = (async_exch_t *) malloc(sizeof(async_exch_t));
    17441746                        if (exch != NULL) {
    1745                                 list_initialize(&exch->sess_link);
    1746                                 list_initialize(&exch->global_link);
     1747                                link_initialize(&exch->sess_link);
     1748                                link_initialize(&exch->global_link);
    17471749                                exch->sess = sess;
    17481750                                exch->phone = sess->phone;
     
    17611763                                exch = (async_exch_t *) malloc(sizeof(async_exch_t));
    17621764                                if (exch != NULL) {
    1763                                         list_initialize(&exch->sess_link);
    1764                                         list_initialize(&exch->global_link);
     1765                                        link_initialize(&exch->sess_link);
     1766                                        link_initialize(&exch->global_link);
    17651767                                        exch->sess = sess;
    17661768                                        exch->phone = phone;
     
    17741776                                 */
    17751777                                exch = (async_exch_t *)
    1776                                     list_get_instance(inactive_exch_list.next, async_exch_t,
    1777                                     global_link);
     1778                                    list_get_instance(list_first(&inactive_exch_list),
     1779                                    async_exch_t, global_link);
     1780                               
    17781781                                list_remove(&exch->sess_link);
    17791782                                list_remove(&exch->global_link);
  • uspace/lib/c/generic/devman.c

    r1d1bb0f rb72efe8  
    3535 */
    3636
     37#include <adt/list.h>
    3738#include <str.h>
    3839#include <ipc/services.h>
     
    231232        }
    232233       
    233         link_t *link = match_ids->ids.next;
    234234        match_id_t *match_id = NULL;
    235235       
    236         while (link != &match_ids->ids) {
     236        list_foreach(match_ids->ids, link) {
    237237                match_id = list_get_instance(link, match_id_t, link);
    238238               
     
    255255                        return retval;
    256256                }
    257                
    258                 link = link->next;
    259257        }
    260258       
  • uspace/lib/c/generic/fibril.c

    r1d1bb0f rb72efe8  
    222222        fibril_t *dstf;
    223223        if ((stype == FIBRIL_TO_MANAGER) || (stype == FIBRIL_FROM_DEAD)) {
    224                 dstf = list_get_instance(manager_list.next, fibril_t, link);
     224                dstf = list_get_instance(list_first(&manager_list), fibril_t,
     225                    link);
    225226                if (serialization_count && stype == FIBRIL_TO_MANAGER) {
    226227                        serialized_threads++;
     
    233234        } else {
    234235                if (!list_empty(&serialized_list)) {
    235                         dstf = list_get_instance(serialized_list.next, fibril_t,
    236                             link);
     236                        dstf = list_get_instance(list_first(&serialized_list),
     237                            fibril_t, link);
    237238                        serialized_threads--;
    238239                } else {
    239                         dstf = list_get_instance(ready_list.next, fibril_t,
    240                             link);
     240                        dstf = list_get_instance(list_first(&ready_list),
     241                            fibril_t, link);
    241242                }
    242243        }
     
    326327       
    327328        if (!list_empty(&manager_list))
    328                 list_remove(manager_list.next);
     329                list_remove(list_first(&manager_list));
    329330       
    330331        futex_up(&fibril_futex);
  • uspace/lib/c/generic/fibril_synch.c

    r1d1bb0f rb72efe8  
    148148                fibril_t *f;
    149149       
    150                 assert(!list_empty(&fm->waiters));
    151                 tmp = fm->waiters.next;
     150                tmp = list_first(&fm->waiters);
     151                assert(tmp != NULL);
    152152                wdp = list_get_instance(tmp, awaiter_t, wu_event.link);
    153153                wdp->active = true;
     
    279279       
    280280        while (!list_empty(&frw->waiters)) {
    281                 link_t *tmp = frw->waiters.next;
     281                link_t *tmp = list_first(&frw->waiters);
    282282                awaiter_t *wdp;
    283283                fibril_t *f;
     
    422422        futex_down(&async_futex);
    423423        while (!list_empty(&fcv->waiters)) {
    424                 tmp = fcv->waiters.next;
     424                tmp = list_first(&fcv->waiters);
    425425                wdp = list_get_instance(tmp, awaiter_t, wu_event.link);
    426426                list_remove(&wdp->wu_event.link);
  • uspace/lib/c/generic/io/io.c

    r1d1bb0f rb72efe8  
    127127void __stdio_done(void)
    128128{
    129         link_t *link = files.next;
    130        
    131         while (link != &files) {
    132                 FILE *file = list_get_instance(link, FILE, link);
     129        while (!list_empty(&files)) {
     130                FILE *file = list_get_instance(list_first(&files), FILE, link);
    133131                fclose(file);
    134                 link = files.next;
    135132        }
    136133}
  • uspace/lib/c/generic/ipc.c

    r1d1bb0f rb72efe8  
    458458        while (!list_empty(&queued_calls)) {
    459459                async_call_t *call =
    460                     list_get_instance(queued_calls.next, async_call_t, list);
     460                    list_get_instance(list_first(&queued_calls), async_call_t, list);
    461461                ipc_callid_t callid =
    462462                    ipc_call_async_internal(call->u.msg.phoneid, &call->u.msg.data);
     
    511511       
    512512        link_t *item;
    513         for (item = dispatched_calls.next; item != &dispatched_calls;
     513        for (item = dispatched_calls.head.next; item != &dispatched_calls.head;
    514514            item = item->next) {
    515515                async_call_t *call =
  • uspace/lib/c/include/adt/hash_table.h

    r1d1bb0f rb72efe8  
    7575/** Hash table structure. */
    7676typedef struct {
    77         link_t *entry;
     77        list_t *entry;
    7878        hash_count_t entries;
    7979        hash_count_t max_keys;
  • uspace/lib/c/include/adt/list.h

    r1d1bb0f rb72efe8  
    11/*
    22 * Copyright (c) 2001-2004 Jakub Jermar
     3 * Copyright (c) 2011 Jiri Svoboda
    34 * All rights reserved.
    45 *
     
    3637#define LIBC_LIST_H_
    3738
     39#include <assert.h>
    3840#include <unistd.h>
    3941
    40 /** Doubly linked list head and link type. */
     42/** Doubly linked list link. */
    4143typedef struct link {
    4244        struct link *prev;  /**< Pointer to the previous item in the list. */
     
    4446} link_t;
    4547
     48/** Doubly linked list. */
     49typedef struct list {
     50        link_t head;  /**< List head. Does not have any data. */
     51} list_t;
     52
    4653/** Declare and initialize statically allocated list.
    4754 *
     
    5057 */
    5158#define LIST_INITIALIZE(name) \
    52         link_t name = { \
    53                 .prev = &name, \
    54                 .next = &name \
     59        list_t name = { \
     60                .head = { \
     61                        .prev = &(name).head, \
     62                        .next = &(name).head \
     63                } \
    5564        }
    5665
     
    5968
    6069#define list_foreach(list, iterator) \
    61         for (link_t *iterator = (list).next; \
    62             iterator != &(list); iterator = iterator->next)
     70        for (link_t *iterator = (list).head.next; \
     71            iterator != &(list).head; iterator = iterator->next)
     72
     73#define assert_link_not_used(link) \
     74        assert((link)->prev == NULL && (link)->next == NULL)
    6375
    6476/** Initialize doubly-linked circular list link
     
    7991 * Initialize doubly-linked circular list.
    8092 *
    81  * @param list Pointer to link_t structure representing the list.
    82  *
    83  */
    84 static inline void list_initialize(link_t *list)
    85 {
    86         list->prev = list;
    87         list->next = list;
     93 * @param list Pointer to list_t structure.
     94 *
     95 */
     96static inline void list_initialize(list_t *list)
     97{
     98        list->head.prev = &list->head;
     99        list->head.next = &list->head;
     100}
     101
     102/** Insert item before another item in doubly-linked circular list.
     103 *
     104 */
     105static inline void list_insert_before(link_t *lnew, link_t *lold)
     106{
     107        lnew->next = lold;
     108        lnew->prev = lold->prev;
     109        lold->prev->next = lnew;
     110        lold->prev = lnew;
     111}
     112
     113/** Insert item after another item in doubly-linked circular list.
     114 *
     115 */
     116static inline void list_insert_after(link_t *lnew, link_t *lold)
     117{
     118        lnew->prev = lold;
     119        lnew->next = lold->next;
     120        lold->next->prev = lnew;
     121        lold->next = lnew;
    88122}
    89123
     
    93127 *
    94128 * @param link Pointer to link_t structure to be added.
    95  * @param list Pointer to link_t structure representing the list.
    96  *
    97  */
    98 static inline void list_prepend(link_t *link, link_t *list)
    99 {
    100         link->next = list->next;
    101         link->prev = list;
    102         list->next->prev = link;
    103         list->next = link;
     129 * @param list Pointer to list_t structure.
     130 *
     131 */
     132static inline void list_prepend(link_t *link, list_t *list)
     133{
     134        list_insert_after(link, &list->head);
    104135}
    105136
     
    109140 *
    110141 * @param link Pointer to link_t structure to be added.
    111  * @param list Pointer to link_t structure representing the list.
    112  *
    113  */
    114 static inline void list_append(link_t *link, link_t *list)
    115 {
    116         link->prev = list->prev;
    117         link->next = list;
    118         list->prev->next = link;
    119         list->prev = link;
    120 }
    121 
    122 /** Insert item before another item in doubly-linked circular list.
    123  *
    124  */
    125 static inline void list_insert_before(link_t *link, link_t *list)
    126 {
    127         list_append(link, list);
    128 }
    129 
    130 /** Insert item after another item in doubly-linked circular list.
    131  *
    132  */
    133 static inline void list_insert_after(link_t *link, link_t *list)
    134 {
    135         list_prepend(list, link);
     142 * @param list Pointer to list_t structure.
     143 *
     144 */
     145static inline void list_append(link_t *link, list_t *list)
     146{
     147        list_insert_before(link, &list->head);
    136148}
    137149
     
    155167 * Query emptiness of doubly-linked circular list.
    156168 *
    157  * @param list Pointer to link_t structure representing the list.
    158  *
    159  */
    160 static inline int list_empty(link_t *list)
    161 {
    162         return (list->next == list);
    163 }
    164 
    165 /** Get head item of a list.
    166  *
    167  * @param list Pointer to link_t structure representing the list.
     169 * @param list Pointer to lins_t structure.
     170 *
     171 */
     172static inline int list_empty(list_t *list)
     173{
     174        return (list->head.next == &list->head);
     175}
     176
     177/** Get first item in list.
     178 *
     179 * @param list Pointer to list_t structure.
    168180 *
    169181 * @return Head item of the list.
     
    171183 *
    172184 */
    173 static inline link_t *list_head(link_t *list)
    174 {
    175         return ((list->next == list) ? NULL : list->next);
     185static inline link_t *list_first(list_t *list)
     186{
     187        return ((list->head.next == &list->head) ? NULL : list->head.next);
     188}
     189
     190/** Get last item in list.
     191 *
     192 * @param list Pointer to list_t structure.
     193 *
     194 * @return Head item of the list.
     195 * @return NULL if the list is empty.
     196 *
     197 */
     198static inline link_t *list_last(list_t *list)
     199{
     200        return ((list->head.prev == &list->head) ? NULL : list->head.prev);
    176201}
    177202
     
    230255}
    231256
    232 /** Get n-th item of a list.
     257/** Get n-th item in a list.
    233258 *
    234259 * @param list Pointer to link_t structure representing the list.
     
    239264 *
    240265 */
    241 static inline link_t *list_nth(link_t *list, unsigned int n)
     266static inline link_t *list_nth(list_t *list, unsigned int n)
    242267{
    243268        unsigned int cnt = 0;
     
    253278}
    254279
    255 extern int list_member(const link_t *, const link_t *);
    256 extern void list_concat(link_t *, link_t *);
    257 extern unsigned int list_count(const link_t *);
     280extern int list_member(const link_t *, const list_t *);
     281extern void list_concat(list_t *, list_t *);
     282extern unsigned int list_count(const list_t *);
    258283
    259284#endif
  • uspace/lib/c/include/adt/prodcons.h

    r1d1bb0f rb72efe8  
    4242        fibril_mutex_t mtx;
    4343        fibril_condvar_t cv;
    44         link_t list;
     44        list_t list;
    4545} prodcons_t;
    4646
  • uspace/lib/c/include/async.h

    r1d1bb0f rb72efe8  
    9999typedef struct {
    100100        /** List of inactive exchanges */
    101         link_t exch_list;
     101        list_t exch_list;
    102102       
    103103        /** Exchange management style */
  • uspace/lib/c/include/fibril_synch.h

    r1d1bb0f rb72efe8  
    4545        fibril_owner_info_t oi;  /**< Keep this the first thing. */
    4646        int counter;
    47         link_t waiters;
     47        list_t waiters;
    4848} fibril_mutex_t;
    4949
     
    5555                .counter = 1, \
    5656                .waiters = { \
    57                         .prev = &name.waiters, \
    58                         .next = &name.waiters, \
     57                        .head = { \
     58                                .prev = &(name).waiters.head, \
     59                                .next = &(name).waiters.head, \
     60                        } \
    5961                } \
    6062        }
     
    6769        unsigned writers;
    6870        unsigned readers;
    69         link_t waiters;
     71        list_t waiters;
    7072} fibril_rwlock_t;
    7173
     
    7880                .writers = 0, \
    7981                .waiters = { \
    80                         .prev = &name.waiters, \
    81                         .next = &name.waiters, \
     82                        .head = { \
     83                                .prev = &(name).waiters.head, \
     84                                .next = &(name).waiters.head, \
     85                        } \
    8286                } \
    8387        }
     
    8791
    8892typedef struct {
    89         link_t waiters;
     93        list_t waiters;
    9094} fibril_condvar_t;
    9195
     
    9397        { \
    9498                .waiters = { \
    95                         .next = &name.waiters, \
    96                         .prev = &name.waiters, \
     99                        .head = { \
     100                                .next = &(name).waiters.head, \
     101                                .prev = &(name).waiters.head, \
     102                        } \
    97103                } \
    98104        }
  • uspace/lib/c/include/ipc/devman.h

    r1d1bb0f rb72efe8  
    7272 */
    7373typedef struct match_id_list {
    74         link_t ids;
     74        list_t ids;
    7575} match_id_list_t;
    7676
     
    9595{
    9696        match_id_t *mid = NULL;
    97         link_t *link = ids->ids.next;
     97        link_t *link = ids->ids.head.next;
    9898       
    99         while (link != &ids->ids) {
     99        while (link != &ids->ids.head) {
    100100                mid = list_get_instance(link, match_id_t,link);
    101101                if (mid->score < id->score) {
    102102                        break;
    103                 }       
     103                }
    104104                link = link->next;
    105105        }
     
    118118        match_id_t *id;
    119119       
    120         while(!list_empty(&ids->ids)) {
    121                 link = ids->ids.next;
    122                 list_remove(link);             
     120        while (!list_empty(&ids->ids)) {
     121                link = list_first(&ids->ids);
     122                list_remove(link);
    123123                id = list_get_instance(link, match_id_t, link);
    124                 delete_match_id(id);           
    125         }       
     124                delete_match_id(id);
     125        }
    126126}
    127127
  • uspace/lib/drv/generic/driver.c

    r1d1bb0f rb72efe8  
    139139find_interrupt_context_by_id(interrupt_context_list_t *list, int id)
    140140{
     141        interrupt_context_t *ctx;
     142       
    141143        fibril_mutex_lock(&list->mutex);
    142144       
    143         link_t *link = list->contexts.next;
    144         interrupt_context_t *ctx;
    145        
    146         while (link != &list->contexts) {
     145        list_foreach(list->contexts, link) {
    147146                ctx = list_get_instance(link, interrupt_context_t, link);
    148147                if (ctx->id == id) {
     
    150149                        return ctx;
    151150                }
    152                 link = link->next;
    153151        }
    154152       
     
    160158find_interrupt_context(interrupt_context_list_t *list, ddf_dev_t *dev, int irq)
    161159{
     160        interrupt_context_t *ctx;
     161       
    162162        fibril_mutex_lock(&list->mutex);
    163163       
    164         link_t *link = list->contexts.next;
    165         interrupt_context_t *ctx;
    166        
    167         while (link != &list->contexts) {
     164        list_foreach(list->contexts, link) {
    168165                ctx = list_get_instance(link, interrupt_context_t, link);
    169166                if (ctx->irq == irq && ctx->dev == dev) {
     
    171168                        return ctx;
    172169                }
    173                 link = link->next;
    174170        }
    175171       
     
    231227}
    232228
    233 static ddf_fun_t *driver_get_function(link_t *functions, devman_handle_t handle)
     229static ddf_fun_t *driver_get_function(list_t *functions, devman_handle_t handle)
    234230{
    235231        ddf_fun_t *fun = NULL;
    236232       
    237233        fibril_mutex_lock(&functions_mutex);
    238         link_t *link = functions->next;
    239        
    240         while (link != functions) {
     234       
     235        list_foreach(*functions, link) {
    241236                fun = list_get_instance(link, ddf_fun_t, link);
    242237                if (fun->handle == handle) {
     
    244239                        return fun;
    245240                }
    246                
    247                 link = link->next;
    248241        }
    249242       
  • uspace/lib/drv/include/ddf/interrupt.h

    r1d1bb0f rb72efe8  
    6060typedef struct interrupt_context_list {
    6161        int curr_id;
    62         link_t contexts;
     62        list_t contexts;
    6363        fibril_mutex_t mutex;
    6464} interrupt_context_list_t;
  • uspace/lib/usbhid/include/usb/hid/hiddescriptor.h

    r1d1bb0f rb72efe8  
    7474                usb_hid_report_path_t *usage_path);
    7575
    76 void usb_hid_descriptor_print_list(link_t *head);
     76void usb_hid_descriptor_print_list(list_t *list);
    7777
    7878void usb_hid_report_reset_local_items(usb_hid_report_item_t *report_item);
    7979
    80 void usb_hid_free_report_list(link_t *head);
     80void usb_hid_free_report_list(list_t *list);
    8181
    8282usb_hid_report_item_t *usb_hid_report_item_clone(
  • uspace/lib/usbhid/include/usb/hid/hidpath.h

    r1d1bb0f rb72efe8  
    8888        uint8_t flags;
    8989
    90         /** Linked list structure*/
    91         link_t link;
     90        /** Link to usb_hid_report_path_t.items list */
     91        link_t rpath_items_link;
    9292} usb_hid_report_usage_path_t;
    9393
     
    9898 * */
    9999typedef struct {
    100         /** Length of usage path */     
    101         int depth;     
     100        /** Length of usage path */
     101        int depth;
    102102
    103103        /** Report id. Zero is reserved and means that report id is not used.
    104104         * */
    105105        uint8_t report_id;
    106        
    107         /** Linked list structure. */   
    108         link_t link; /* list */
    109106
    110         /** Head of the list of usage path items. */
    111         link_t head;
     107        /** Link to usb_hid_report_path_t.collection_paths list. */
     108        link_t cpath_link;
    112109
     110        /** List of usage path items. */
     111        list_t items;   /* of usb_hid_report_usage_path_t */
    113112} usb_hid_report_path_t;
    114113
  • uspace/lib/usbhid/include/usb/hid/hidtypes.h

    r1d1bb0f rb72efe8  
    9595        int report_count;
    9696
    97         /** Head of linked list of description of reports. */
    98         link_t reports;
    99 
    100         /** Head of linked list of all used usage/collection paths. */
    101         link_t collection_paths;
     97        /** List of description of reports. */
     98        list_t reports; /* of usb_hid_report_description_t */
     99
     100        /** List of all used usage/collection paths. */
     101        list_t collection_paths;
    102102
    103103        /** Length of list of usage paths. */
     
    129129        size_t item_length;
    130130       
    131         /** Linked list of report items in report */
    132         link_t report_items;
    133 
    134         /** Linked list of descriptions. */
    135         link_t link;
     131        /** List of report items in report */
     132        list_t report_items;
     133
     134        /** Link to usb_hid_report_t.reports list. */
     135        link_t reports_link;
    136136} usb_hid_report_description_t;
    137137/*---------------------------------------------------------------------------*/
     
    198198        int32_t value;
    199199
    200         /** List to another report items */
    201         link_t link;
     200        /** Link to usb_hid_report_description_t.report_items list */
     201        link_t ritems_link;
    202202} usb_hid_report_field_t;
    203203
  • uspace/lib/usbhid/src/hiddescriptor.c

    r1d1bb0f rb72efe8  
    8888 * @retval NULL If some error occurs
    8989 */
    90 usb_hid_report_path_t *usb_hid_report_path_try_insert(
    91                 usb_hid_report_t *report, usb_hid_report_path_t *cmp_path) {
    92        
    93         link_t *path_it = report->collection_paths.next;
     90usb_hid_report_path_t *usb_hid_report_path_try_insert(usb_hid_report_t *report,
     91    usb_hid_report_path_t *cmp_path)
     92{
     93        link_t *path_it = report->collection_paths.head.next;
    9494        usb_hid_report_path_t *path = NULL;
    9595       
     
    9898        }
    9999       
    100         while(path_it != &report->collection_paths) {
     100        while(path_it != &report->collection_paths.head) {
    101101                path = list_get_instance(path_it, usb_hid_report_path_t,
    102                                 link);
     102                                cpath_link);
    103103               
    104104                if(usb_hid_report_compare_usage_path(path, cmp_path,
    105105                                        USB_HID_PATH_COMPARE_STRICT) == EOK){
    106106                        break;
    107                 }                       
     107                }
    108108                path_it = path_it->next;
    109109        }
    110         if(path_it == &report->collection_paths) {
     110        if(path_it == &report->collection_paths.head) {
    111111                path = usb_hid_report_path_clone(cmp_path);
    112112                if(path == NULL) {
    113113                        return NULL;
    114114                }
    115                 list_append(&path->link, &report->collection_paths);                                   
     115                list_append(&path->cpath_link, &report->collection_paths);
    116116                report->collection_paths_count++;
    117117
     
    120120        else {
    121121                return list_get_instance(path_it, usb_hid_report_path_t,
    122                                 link);
     122                                cpath_link);
    123123        }
    124124}
     
    192192
    193193                memset(field, 0, sizeof(usb_hid_report_field_t));
    194                 list_initialize(&field->link);
     194                link_initialize(&field->ritems_link);
    195195
    196196                /* fill the attributes */               
     
    291291                        }
    292292
    293                         list_initialize (&report_des->link);
     293                        link_initialize (&report_des->reports_link);
    294294                        list_initialize (&report_des->report_items);
    295295
    296                         list_append(&report_des->link, &report->reports);
     296                        list_append(&report_des->reports_link, &report->reports);
    297297                        report->report_count++;
    298298                }
    299299
    300300                /* append this field to the end of founded report list */
    301                 list_append (&field->link, &report_des->report_items);
     301                list_append(&field->ritems_link, &report_des->report_items);
    302302               
    303303                /* update the sizes */
     
    333333        }
    334334
    335         link_t *report_it = report->reports.next;
    336335        usb_hid_report_description_t *report_des = NULL;
    337336       
    338         while(report_it != &report->reports) {
     337        list_foreach(report->reports, report_it) {
    339338                report_des = list_get_instance(report_it,
    340                                 usb_hid_report_description_t, link);
     339                                usb_hid_report_description_t, reports_link);
    341340
    342341                // if report id not set, return the first of the type
     
    345344                        return report_des;
    346345                }
    347                
    348                 report_it = report_it->next;
    349346        }
    350347
     
    377374        size_t offset_output=0;
    378375        size_t offset_feature=0;
    379 
    380         link_t stack;
    381         list_initialize(&stack);       
     376       
     377        link_t *item_link;
     378
     379        list_t stack;
     380        list_initialize(&stack);
    382381
    383382        /* parser structure initialization*/
     
    391390        }
    392391        memset(report_item, 0, sizeof(usb_hid_report_item_t));
    393         list_initialize(&(report_item->link)); 
     392        link_initialize(&(report_item->link));
    394393
    395394        /* usage path context initialization */
     
    493492                        case USB_HID_REPORT_TAG_POP:
    494493                                // restore current state from stack
    495                                 if(list_empty (&stack)) {
     494                                item_link = list_first(&stack);
     495                                if (item_link == NULL) {
    496496                                        return EINVAL;
    497497                                }
    498498                                free(report_item);
    499                                                
    500                                 report_item = list_get_instance(stack.next,
     499                               
     500                                report_item = list_get_instance(item_link,
    501501                                    usb_hid_report_item_t, link);
    502                                        
     502                               
    503503                                usb_hid_report_usage_path_t *tmp_usage_path;
    504504                                tmp_usage_path = list_get_instance(
    505                                     report_item->usage_path->link.prev,
    506                                     usb_hid_report_usage_path_t, link);
    507                                        
     505                                    report_item->usage_path->cpath_link.prev,
     506                                    usb_hid_report_usage_path_t, rpath_items_link);
     507                               
    508508                                usb_hid_report_set_last_item(usage_path,
    509509                                    USB_HID_TAG_CLASS_GLOBAL, tmp_usage_path->usage_page);
     
    513513
    514514                                usb_hid_report_path_free(report_item->usage_path);
    515                                 list_remove (stack.next);
     515                                list_remove (item_link);
    516516                                       
    517517                                break;
     
    609609
    610610                /* store collection atributes */
    611                 path_item = list_get_instance(usage_path->head.prev,
    612                         usb_hid_report_usage_path_t, link);
    613                 path_item->flags = *data;       
     611                path_item = list_get_instance(list_first(&usage_path->items),
     612                        usb_hid_report_usage_path_t, rpath_items_link);
     613                path_item->flags = *data;
    614614                       
    615615                /* set last item */
     
    900900 * @return void
    901901 */
    902 void usb_hid_descriptor_print_list(link_t *head)
     902void usb_hid_descriptor_print_list(list_t *list)
    903903{
    904904        usb_hid_report_field_t *report_item;
    905         link_t *item;
    906 
    907 
    908         if(head == NULL || list_empty(head)) {
     905
     906        if(list == NULL || list_empty(list)) {
    909907            usb_log_debug("\tempty\n");
    910908            return;
    911909        }
    912        
    913         for(item = head->next; item != head; item = item->next) {
    914                
    915                 report_item = list_get_instance(item, usb_hid_report_field_t,
    916                                 link);
     910
     911        list_foreach(*list, item) {
     912                report_item = list_get_instance(item, usb_hid_report_field_t,
     913                                ritems_link);
    917914
    918915                usb_log_debug("\t\tOFFSET: %X\n", report_item->offset);
    919916                usb_log_debug("\t\tSIZE: %zu\n", report_item->size);
    920                 usb_log_debug("\t\tLOGMIN: %d\n", 
     917                usb_log_debug("\t\tLOGMIN: %d\n",
    921918                        report_item->logical_minimum);
    922                 usb_log_debug("\t\tLOGMAX: %d\n", 
    923                         report_item->logical_maximum);         
    924                 usb_log_debug("\t\tPHYMIN: %d\n", 
    925                         report_item->physical_minimum);         
    926                 usb_log_debug("\t\tPHYMAX: %d\n", 
    927                         report_item->physical_maximum);                         
    928                 usb_log_debug("\t\ttUSAGEMIN: %X\n", 
     919                usb_log_debug("\t\tLOGMAX: %d\n",
     920                        report_item->logical_maximum);
     921                usb_log_debug("\t\tPHYMIN: %d\n",
     922                        report_item->physical_minimum);
     923                usb_log_debug("\t\tPHYMAX: %d\n",
     924                        report_item->physical_maximum);
     925                usb_log_debug("\t\ttUSAGEMIN: %X\n",
    929926                        report_item->usage_minimum);
    930927                usb_log_debug("\t\tUSAGEMAX: %X\n",
    931928                               report_item->usage_maximum);
    932                 usb_log_debug("\t\tUSAGES COUNT: %zu\n", 
     929                usb_log_debug("\t\tUSAGES COUNT: %zu\n",
    933930                        report_item->usages_count);
    934931
     
    936933                usb_log_debug("\t\ttUSAGE: %X\n", report_item->usage);
    937934                usb_log_debug("\t\tUSAGE PAGE: %X\n", report_item->usage_page);
    938                
     935
    939936                usb_hid_print_usage_path(report_item->collection_path);
    940937
    941                 usb_log_debug("\n");           
     938                usb_log_debug("\n");
    942939
    943940        }
     
    958955        }
    959956
    960         link_t *report_it = report->reports.next;
    961957        usb_hid_report_description_t *report_des;
    962958
    963         while(report_it != &report->reports) {
    964                 report_des = list_get_instance(report_it, 
    965                         usb_hid_report_description_t, link);
     959        list_foreach(report->reports, report_it) {
     960                report_des = list_get_instance(report_it,
     961                        usb_hid_report_description_t, reports_link);
    966962                usb_log_debug("Report ID: %d\n", report_des->report_id);
    967963                usb_log_debug("\tType: %d\n", report_des->type);
    968                 usb_log_debug("\tLength: %zu\n", report_des->bit_length);               
     964                usb_log_debug("\tLength: %zu\n", report_des->bit_length);
    969965                usb_log_debug("\tB Size: %zu\n",
    970                         usb_hid_report_byte_size(report, 
    971                                 report_des->report_id, 
     966                        usb_hid_report_byte_size(report,
     967                                report_des->report_id,
    972968                                report_des->type));
    973                 usb_log_debug("\tItems: %zu\n", report_des->item_length);               
     969                usb_log_debug("\tItems: %zu\n", report_des->item_length);
    974970
    975971                usb_hid_descriptor_print_list(&report_des->report_items);
    976 
    977                 report_it = report_it->next;
    978972        }
    979973}
     
    983977 * Releases whole linked list of report items
    984978 *
    985  * @param head Head of list of report descriptor items (usb_hid_report_item_t)
     979 * @param list List of report descriptor items (usb_hid_report_item_t)
    986980 * @return void
    987981 */
    988 void usb_hid_free_report_list(link_t *head)
     982void usb_hid_free_report_list(list_t *list)
    989983{
    990         return;
    991        
    992         usb_hid_report_item_t *report_item;
     984        return; /* XXX What's this? */
     985       
     986/*      usb_hid_report_item_t *report_item;
    993987        link_t *next;
    994988       
    995         if(head == NULL || list_empty(head)) {         
     989        if(list == NULL || list_empty(list)) {
    996990            return;
    997991        }
    998992       
    999         next = head->next;
    1000         while(next != head) {
    1001        
    1002             report_item = list_get_instance(next, usb_hid_report_item_t, link);
     993        next = list->head.next;
     994        while (next != &list->head) {
     995                report_item = list_get_instance(next, usb_hid_report_item_t,
     996                    rpath_items_link);
    1003997
    1004998                while(!list_empty(&report_item->usage_path->link)) {
    1005                     usb_hid_report_remove_last_item(report_item->usage_path);
     999                        usb_hid_report_remove_last_item(report_item->usage_path);
    10061000                }
    10071001
     
    10131007       
    10141008        return;
    1015        
     1009        */
    10161010}
    10171011/*---------------------------------------------------------------------------*/
     
    10291023
    10301024        // free collection paths
     1025        link_t *path_link;
    10311026        usb_hid_report_path_t *path;
    10321027        while(!list_empty(&report->collection_paths)) {
    1033                 path = list_get_instance(report->collection_paths.next,
    1034                                 usb_hid_report_path_t, link);
    1035 
    1036                 usb_hid_report_path_free(path);         
     1028                path_link = list_first(&report->collection_paths);
     1029                path = list_get_instance(path_link,
     1030                    usb_hid_report_path_t, cpath_link);
     1031
     1032                list_remove(path_link);
     1033                usb_hid_report_path_free(path);
    10371034        }
    10381035       
     
    10411038        usb_hid_report_field_t *field;
    10421039        while(!list_empty(&report->reports)) {
    1043                 report_des = list_get_instance(report->reports.next,
    1044                                 usb_hid_report_description_t, link);
    1045 
    1046                 list_remove(&report_des->link);
     1040                report_des = list_get_instance(list_first(&report->reports),
     1041                                usb_hid_report_description_t, reports_link);
     1042
     1043                list_remove(&report_des->reports_link);
    10471044               
    10481045                while(!list_empty(&report_des->report_items)) {
    10491046                        field = list_get_instance(
    1050                                 report_des->report_items.next,
    1051                                 usb_hid_report_field_t, link);
    1052 
    1053                         list_remove(&field->link);
     1047                            list_first(&report_des->report_items),
     1048                            usb_hid_report_field_t, ritems_link);
     1049
     1050                        list_remove(&field->ritems_link);
    10541051
    10551052                        free(field);
  • uspace/lib/usbhid/src/hidparser.c

    r1d1bb0f rb72efe8  
    135135        size_t size, uint8_t *report_id)
    136136{
    137         link_t *list_item;
    138137        usb_hid_report_field_t *item;
    139138
     
    161160
    162161        /* read data */
    163         list_item = report_des->report_items.next;         
    164         while(list_item != &(report_des->report_items)) {
    165 
     162        list_foreach(report_des->report_items, list_item) {
    166163                item = list_get_instance(list_item, usb_hid_report_field_t,
    167                                 link);
     164                                ritems_link);
    168165
    169166                if(USB_HID_ITEM_FLAG_CONSTANT(item->item_flags) == 0) {
     
    200197                        }                       
    201198                }
    202                 list_item = list_item->next;
    203199        }
    204200       
     
    310306        }
    311307
    312         link_t *report_it = report->reports.next;
    313308        usb_hid_report_description_t *report_des = NULL;
    314         while(report_it != &report->reports) {
    315                 report_des = list_get_instance(report_it,
    316                         usb_hid_report_description_t, link);
     309
     310        list_foreach(report->reports, report_it) {
     311                report_des = list_get_instance(report_it,
     312                        usb_hid_report_description_t, reports_link);
    317313               
    318                 if((report_des->report_id == report_id) && 
     314                if((report_des->report_id == report_id) &&
    319315                        (report_des->type == USB_HID_REPORT_TYPE_OUTPUT)){
    320316                        break;
    321317                }
    322 
    323                 report_it = report_it->next;
    324318        }
    325319
     
    362356        uint8_t report_id, uint8_t *buffer, size_t size)
    363357{
    364         link_t *item;   
    365358        int32_t value=0;
    366359        int offset;
     
    384377        }
    385378
    386         usb_hid_report_field_t *report_item;   
    387         item = report_des->report_items.next;   
    388         while(item != &report_des->report_items) {
    389                 report_item = list_get_instance(item, usb_hid_report_field_t, link);
     379        usb_hid_report_field_t *report_item;
     380
     381        list_foreach(report_des->report_items, item) {
     382                report_item = list_get_instance(item, usb_hid_report_field_t,
     383                    ritems_link);
    390384
    391385                value = usb_hid_translate_data_reverse(report_item,
     
    449443                // reset value
    450444                report_item->value = 0;
    451                
    452                 item = item->next;
    453445        }
    454446       
     
    550542
    551543        if(field == NULL){
    552                 field_it = report_des->report_items.next;
    553         }
    554         else {
    555                 field_it = field->link.next;
    556         }
    557 
    558         while(field_it != &report_des->report_items) {
     544                field_it = report_des->report_items.head.next;
     545        }
     546        else {
     547                field_it = field->ritems_link.next;
     548        }
     549
     550        while(field_it != &report_des->report_items.head) {
    559551                field = list_get_instance(field_it, usb_hid_report_field_t,
    560                         link);
     552                        ritems_link);
    561553
    562554                if(USB_HID_ITEM_FLAG_CONSTANT(field->item_flags) == 0) {
     
    611603                }
    612604                else {
    613                         report_it = report_des->link.next;
     605                        report_it = report_des->reports_link.next;
    614606                }       
    615607        }
    616608        else {
    617                 report_it = report->reports.next;
    618         }
    619 
    620         while(report_it != &report->reports) {
     609                report_it = report->reports.head.next;
     610        }
     611
     612        while(report_it != &report->reports.head) {
    621613                report_des = list_get_instance(report_it,
    622                         usb_hid_report_description_t, link);
     614                        usb_hid_report_description_t, reports_link);
    623615
    624616                if(report_des->type == type){
  • uspace/lib/usbhid/src/hidpath.c

    r1d1bb0f rb72efe8  
    8181                return ENOMEM;
    8282        }
    83         list_initialize(&item->link);
     83        link_initialize(&item->rpath_items_link);
    8484
    8585        item->usage = usage;
     
    8787        item->flags = 0;
    8888       
    89         list_append (&item->link, &usage_path->head);
     89        list_append (&item->rpath_items_link, &usage_path->items);
    9090        usage_path->depth++;
    9191        return EOK;
     
    100100void usb_hid_report_remove_last_item(usb_hid_report_path_t *usage_path)
    101101{
     102        link_t *item_link;
    102103        usb_hid_report_usage_path_t *item;
    103104       
    104         if(!list_empty(&usage_path->head)){
    105                 item = list_get_instance(usage_path->head.prev,
    106                                          usb_hid_report_usage_path_t, link);           
    107                 list_remove(usage_path->head.prev);
     105        if(!list_empty(&usage_path->items)){
     106                item_link = list_last(&usage_path->items);
     107                item = list_get_instance(item_link,
     108                    usb_hid_report_usage_path_t, rpath_items_link);
     109                list_remove(item_link);
    108110                usage_path->depth--;
    109111                free(item);
     
    122124        usb_hid_report_usage_path_t *item;
    123125       
    124         if(!list_empty(&usage_path->head)){     
    125                 item = list_get_instance(usage_path->head.prev,
    126                         usb_hid_report_usage_path_t, link);
     126        if(!list_empty(&usage_path->items)){
     127                item = list_get_instance(list_last(&usage_path->items),
     128                        usb_hid_report_usage_path_t, rpath_items_link);
    127129
    128130                memset(item, 0, sizeof(usb_hid_report_usage_path_t));
     
    145147        usb_hid_report_usage_path_t *item;
    146148       
    147         if(!list_empty(&usage_path->head)){     
    148                 item = list_get_instance(usage_path->head.prev,
    149                                          usb_hid_report_usage_path_t, link);
     149        if(!list_empty(&usage_path->items)){
     150                item = list_get_instance(list_last(&usage_path->items),
     151                     usb_hid_report_usage_path_t, rpath_items_link);
    150152
    151153                switch(tag) {
     
    173175        usb_log_debug("\tLENGTH: %d\n", path->depth);
    174176
    175         link_t *item = path->head.next;
    176177        usb_hid_report_usage_path_t *path_item;
    177         while(item != &path->head) {
    178 
    179                 path_item = list_get_instance(item, usb_hid_report_usage_path_t, 
    180                         link);
     178
     179        list_foreach(path->items, item) {
     180                path_item = list_get_instance(item, usb_hid_report_usage_path_t,
     181                        rpath_items_link);
    181182
    182183                usb_log_debug("\tUSAGE_PAGE: %X\n", path_item->usage_page);
    183184                usb_log_debug("\tUSAGE: %X\n", path_item->usage);
    184                 usb_log_debug("\tFLAGS: %d\n", path_item->flags);               
    185                
    186         item = item->next;
     185                usb_log_debug("\tFLAGS: %d\n", path_item->flags);
    187186        }
    188187}
     
    233232                }
    234233
    235                 report_link = report_path->head.next;
    236                 path_link = path->head.next;
    237                 path_item = list_get_instance(path_link,
    238                         usb_hid_report_usage_path_t, link);
    239 
    240                 while(report_link != &report_path->head) {
    241                         report_item = list_get_instance(report_link,
    242                                 usb_hid_report_usage_path_t, link);
     234                path_link = list_first(&path->items);
     235                path_item = list_get_instance(path_link,
     236                        usb_hid_report_usage_path_t, rpath_items_link);
     237
     238                list_foreach(report_path->items, report_link) {
     239                        report_item = list_get_instance(report_link,
     240                                usb_hid_report_usage_path_t, rpath_items_link);
    243241                               
    244                         if(USB_HID_SAME_USAGE_PAGE(report_item->usage_page, 
     242                        if(USB_HID_SAME_USAGE_PAGE(report_item->usage_page,
    245243                                path_item->usage_page)){
    246244                                       
     
    257255                                }
    258256                        }
    259 
    260                         report_link = report_link->next;
    261257                }
    262258
     
    273269        case USB_HID_PATH_COMPARE_BEGIN:
    274270       
    275                 report_link = report_path->head.next;
    276                 path_link = path->head.next;
     271                report_link = report_path->items.head.next;
     272                path_link = path->items.head.next;
    277273                       
    278                 while((report_link != &report_path->head) &&
    279                       (path_link != &path->head)) {
     274                while((report_link != &report_path->items.head) &&
     275                      (path_link != &path->items.head)) {
    280276                                         
    281277                        report_item = list_get_instance(report_link,
    282                                 usb_hid_report_usage_path_t, link);
     278                                usb_hid_report_usage_path_t, rpath_items_link);
    283279                                         
    284280                        path_item = list_get_instance(path_link,
    285                                 usb_hid_report_usage_path_t, link);
     281                                usb_hid_report_usage_path_t, rpath_items_link);
    286282
    287283                        if(!USB_HID_SAME_USAGE_PAGE(report_item->usage_page,
     
    297293                        }
    298294                       
    299                                 }
     295                }
    300296
    301297                if((((flags & USB_HID_PATH_COMPARE_BEGIN) != 0) &&
    302                         (path_link == &path->head)) ||
    303                    ((report_link == &report_path->head) &&
    304                         (path_link == &path->head))) {
     298                        (path_link == &path->items.head)) ||
     299                   ((report_link == &report_path->items.head) &&
     300                        (path_link == &path->items.head))) {
    305301                               
    306302                        return EOK;
     
    314310        case USB_HID_PATH_COMPARE_END:
    315311
    316                 report_link = report_path->head.prev;
    317                 path_link = path->head.prev;
    318 
    319                 if(list_empty(&path->head)){
     312                report_link = report_path->items.head.prev;
     313                path_link = path->items.head.prev;
     314
     315                if(list_empty(&path->items)){
    320316                        return EOK;
    321317                }
    322318                       
    323                 while((report_link != &report_path->head) &&
    324                       (path_link != &path->head)) {
     319                while((report_link != &report_path->items.head) &&
     320                      (path_link != &path->items.head)) {
    325321                                                 
    326                         report_item = list_get_instance(report_link, 
    327                                 usb_hid_report_usage_path_t, link);
     322                        report_item = list_get_instance(report_link,
     323                                usb_hid_report_usage_path_t, rpath_items_link);
    328324
    329325                        path_item = list_get_instance(path_link,
    330                                 usb_hid_report_usage_path_t, link);             
     326                                usb_hid_report_usage_path_t, rpath_items_link);
    331327                                                 
    332328                        if(!USB_HID_SAME_USAGE_PAGE(report_item->usage_page,
     
    343339                }
    344340
    345                 if(path_link == &path->head) {
     341                if(path_link == &path->items.head) {
    346342                        return EOK;
    347343                }
     
    373369                path->depth = 0;
    374370                path->report_id = 0;
    375                 list_initialize(&path->link);
    376                 list_initialize(&path->head);
     371                link_initialize(&path->cpath_link);
     372                list_initialize(&path->items);
    377373                return path;
    378374        }
     
    388384void usb_hid_report_path_free(usb_hid_report_path_t *path)
    389385{
    390         while(!list_empty(&path->head)){
     386        while(!list_empty(&path->items)){
    391387                usb_hid_report_remove_last_item(path);
    392388        }
    393389
    394         list_remove(&path->link);
     390        assert_link_not_used(&path->cpath_link);
    395391        free(path);
    396392}
     
    406402        usb_hid_report_path_t *usage_path)
    407403{
    408         link_t *path_link;
    409404        usb_hid_report_usage_path_t *path_item;
    410405        usb_hid_report_usage_path_t *new_path_item;
     
    417412        new_usage_path->report_id = usage_path->report_id;
    418413       
    419         if(list_empty(&usage_path->head)){
     414        if(list_empty(&usage_path->items)){
    420415                return new_usage_path;
    421416        }
    422417
    423         path_link = usage_path->head.next;
    424         while(path_link != &usage_path->head) {
    425                 path_item = list_get_instance(path_link,
    426                         usb_hid_report_usage_path_t, link);
     418        list_foreach(usage_path->items, path_link) {
     419                path_item = list_get_instance(path_link,
     420                        usb_hid_report_usage_path_t, rpath_items_link);
    427421
    428422                new_path_item = malloc(sizeof(usb_hid_report_usage_path_t));
     
    431425                }
    432426               
    433                 list_initialize (&new_path_item->link);         
     427                link_initialize(&new_path_item->rpath_items_link);
    434428                new_path_item->usage_page = path_item->usage_page;
    435429                new_path_item->usage = path_item->usage;               
    436430                new_path_item->flags = path_item->flags;               
    437431               
    438                 list_append(&new_path_item->link, &new_usage_path->head);
     432                list_append(&new_path_item->rpath_items_link,
     433                    &new_usage_path->items);
    439434                new_usage_path->depth++;
    440 
    441                 path_link = path_link->next;
    442435        }
    443436
Note: See TracChangeset for help on using the changeset viewer.