Changeset b72efe8 in mainline for uspace/lib/c/generic/adt


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/c/generic/adt
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • 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       
Note: See TracChangeset for help on using the changeset viewer.