Changeset f959a20f in mainline


Ignore:
Timestamp:
2019-02-01T22:32:38Z (5 years ago)
Author:
Jiří Zárevúcky <zarevucky.jiri@…>
Children:
00b7fc8
Parents:
1a37496
git-author:
Jiří Zárevúcky <zarevucky.jiri@…> (2019-02-01 21:22:39)
git-committer:
Jiří Zárevúcky <zarevucky.jiri@…> (2019-02-01 22:32:38)
Message:

Avoid directly using .head/.next/.prev of list_t/link_t

Use existing constructs from <adt/list.h> instead.

Location:
uspace
Files:
19 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/bus/usb/ehci/endpoint_list.c

    r1a37496 rf959a20f  
    160160        const char *qpos = NULL;
    161161        qh_t *prev_qh;
     162        link_t *prev = list_prev(&ep->eplist_link, &instance->endpoint_list);
     163
    162164        /* Remove from the hardware queue */
    163         if (list_first(&instance->endpoint_list) == &ep->eplist_link) {
     165        if (!prev) {
    164166                /* I'm the first one here */
    165167                prev_qh = instance->list_head;
    166168                qpos = "FIRST";
    167169        } else {
    168                 prev_qh = ehci_endpoint_list_instance(ep->eplist_link.prev)->qh;
     170                prev_qh = ehci_endpoint_list_instance(prev)->qh;
    169171                qpos = "NOT FIRST";
    170172        }
  • uspace/drv/bus/usb/ohci/endpoint_list.c

    r1a37496 rf959a20f  
    156156        const char *qpos = NULL;
    157157        ed_t *prev_ed;
     158        link_t *prev_link = list_prev(&ep->eplist_link, &instance->endpoint_list);
    158159        /* Remove from the hardware queue */
    159         if (list_first(&instance->endpoint_list) == &ep->eplist_link) {
     160        if (!prev_link) {
    160161                /* I'm the first one here */
    161162                prev_ed = instance->list_head;
     
    163164        } else {
    164165                ohci_endpoint_t *prev =
    165                     list_get_instance(ep->eplist_link.prev, ohci_endpoint_t, eplist_link);
     166                    list_get_instance(prev_link, ohci_endpoint_t, eplist_link);
    166167                prev_ed = prev->ed;
    167168                qpos = "NOT FIRST";
  • uspace/drv/bus/usb/uhci/transfer_list.c

    r1a37496 rf959a20f  
    233233        const char *qpos = "FIRST";
    234234        qh_t *prev_qh = instance->queue_head;
     235        link_t *prev = list_prev(&uhci_batch->link, &instance->batch_list);
    235236        /* Remove from the hardware queue */
    236         if (list_first(&instance->batch_list) != &uhci_batch->link) {
     237        if (prev) {
    237238                /* There is a batch in front of me */
    238                 prev_qh =
    239                     uhci_transfer_batch_from_link(uhci_batch->link.prev)->qh;
     239                prev_qh = uhci_transfer_batch_from_link(prev)->qh;
    240240                qpos = "NOT FIRST";
    241241        }
  • uspace/lib/c/generic/adt/hash_table.c

    r1a37496 rf959a20f  
    273273
    274274        size_t idx = h->op->hash(item) % h->bucket_cnt;
     275        list_t *list = &h->bucket[idx];
    275276
    276277        /* Traverse the circular list until we reach the starting item again. */
    277         for (link_t *cur = item->link.next; cur != &first->link;
    278             cur = cur->next) {
    279                 assert(cur);
    280 
    281                 if (cur == &h->bucket[idx].head)
    282                         continue;
     278        for (link_t *cur = list_next(&item->link, list); cur != &first->link;
     279            cur = list_next(cur, list)) {
     280
     281                if (!cur)
     282                        cur = list_first(list);
    283283
    284284                ht_link_t *cur_link = member_to_inst(cur, ht_link_t, link);
  • uspace/lib/c/generic/thread/fibril.c

    r1a37496 rf959a20f  
    601601        assert(timeout);
    602602
    603         link_t *tmp = timeout_list.head.next;
    604         while (tmp != &timeout_list.head) {
    605                 _timeout_t *cur = list_get_instance(tmp, _timeout_t, link);
    606 
    607                 if (ts_gteq(&cur->expires, &timeout->expires))
    608                         break;
    609 
    610                 tmp = tmp->next;
    611         }
    612 
    613         list_insert_before(&timeout->link, tmp);
     603        list_foreach(timeout_list, link, _timeout_t, cur) {
     604                if (ts_gteq(&cur->expires, &timeout->expires)) {
     605                        list_insert_before(&timeout->link, &cur->link);
     606                        return;
     607                }
     608        }
     609
     610        list_append(&timeout->link, &timeout_list);
    614611}
    615612
  • uspace/lib/c/include/ipc/devman.h

    r1a37496 rf959a20f  
    108108static inline void add_match_id(match_id_list_t *ids, match_id_t *id)
    109109{
    110         match_id_t *mid = NULL;
    111         link_t *link = ids->ids.head.next;
    112 
    113         while (link != &ids->ids.head) {
    114                 mid = list_get_instance(link, match_id_t, link);
     110        list_foreach(ids->ids, link, match_id_t, mid) {
    115111                if (mid->score < id->score) {
    116                         break;
     112                        list_insert_before(&id->link, &mid->link);
     113                        return;
    117114                }
    118                 link = link->next;
    119115        }
    120116
    121         list_insert_before(&id->link, link);
     117        list_append(&id->link, &ids->ids);
    122118}
    123119
  • uspace/lib/nic/include/nic.h

    r1a37496 rf959a20f  
    7171} nic_frame_t;
    7272
    73 typedef list_t nic_frame_list_t;
     73typedef union {
     74        list_t list;
     75        link_t link;
     76} nic_frame_list_t;
    7477
    7578/**
  • uspace/lib/nic/src/nic_driver.c

    r1a37496 rf959a20f  
    329329
    330330        if (nic_globals.frame_list_cache_size > 0) {
    331                 frames =
    332                     list_get_instance(list_first(&nic_globals.frame_list_cache),
    333                     nic_frame_list_t, head);
    334                 list_remove(&frames->head);
    335                 list_initialize(frames);
     331                frames = list_pop(&nic_globals.frame_list_cache,
     332                    nic_frame_list_t, link);
     333                assert(frames);
     334                list_initialize(&frames->list);
    336335                nic_globals.frame_list_cache_size--;
    337336                fibril_mutex_unlock(&nic_globals.lock);
     
    341340                frames = malloc(sizeof (nic_frame_list_t));
    342341                if (frames != NULL)
    343                         list_initialize(frames);
     342                        list_initialize(&frames->list);
    344343        }
    345344
     
    356355                free(frames);
    357356        } else {
    358                 list_prepend(&frames->head, &nic_globals.frame_list_cache);
     357                list_prepend(&frames->link, &nic_globals.frame_list_cache);
    359358                nic_globals.frame_list_cache_size++;
    360359                fibril_mutex_unlock(&nic_globals.lock);
     
    372371{
    373372        assert(frame != NULL && frames != NULL);
    374         list_append(&frame->link, frames);
     373        list_append(&frame->link, &frames->list);
    375374}
    376375
     
    576575        if (frames == NULL)
    577576                return;
    578         while (!list_empty(frames)) {
    579                 nic_frame_t *frame =
    580                     list_get_instance(list_first(frames), nic_frame_t, link);
    581 
    582                 list_remove(&frame->link);
     577        while (!list_empty(&frames->list)) {
     578                nic_frame_t *frame = list_pop(&frames->list, nic_frame_t, link);
    583579                nic_received_frame(nic_data, frame);
    584580        }
  • uspace/lib/posix/src/signal.c

    r1a37496 rf959a20f  
    383383static void _dequeue_unblocked_signals(void)
    384384{
    385         link_t *iterator = _signal_queue.head.next;
    386         link_t *next;
    387 
    388         while (iterator != &(_signal_queue).head) {
    389                 next = iterator->next;
    390 
     385        list_foreach_safe(_signal_queue, cur_link, next_link) {
    391386                signal_queue_item *item =
    392                     list_get_instance(iterator, signal_queue_item, link);
     387                    list_get_instance(cur_link, signal_queue_item, link);
    393388
    394389                if (!sigismember(&_signal_mask, item->signo) &&
    395390                    _signal_actions[item->signo].sa_handler != SIG_HOLD) {
    396                         list_remove(&(item->link));
    397                         _raise_sigaction(item->signo, &(item->siginfo));
     391                        list_remove(cur_link);
     392                        _raise_sigaction(item->signo, &item->siginfo);
    398393                        free(item);
    399394                }
    400 
    401                 iterator = next;
    402395        }
    403396}
  • uspace/lib/usbhid/src/hiddescriptor.c

    r1a37496 rf959a20f  
    8989    usb_hid_report_path_t *cmp_path)
    9090{
    91         link_t *path_it = report->collection_paths.head.next;
    92         usb_hid_report_path_t *path = NULL;
    93 
    94         if ((report == NULL) || (cmp_path == NULL)) {
     91        if (report == NULL || cmp_path == NULL)
    9592                return NULL;
    96         }
    97 
    98         while (path_it != &report->collection_paths.head) {
    99                 path = list_get_instance(path_it, usb_hid_report_path_t,
    100                     cpath_link);
    101 
     93
     94        list_foreach(report->collection_paths, cpath_link, usb_hid_report_path_t, path) {
    10295                if (usb_hid_report_compare_usage_path(path, cmp_path,
    103                     USB_HID_PATH_COMPARE_STRICT) == 0) {
    104                         break;
    105                 }
    106                 path_it = path_it->next;
    107         }
    108         if (path_it == &report->collection_paths.head) {
    109                 path = usb_hid_report_path_clone(cmp_path);
    110                 if (path == NULL) {
    111                         return NULL;
    112                 }
    113                 list_append(&path->cpath_link, &report->collection_paths);
    114                 report->collection_paths_count++;
    115 
    116                 return path;
    117         } else {
    118                 return list_get_instance(path_it, usb_hid_report_path_t,
    119                     cpath_link);
    120         }
     96                    USB_HID_PATH_COMPARE_STRICT) == 0)
     97                        return path;
     98        }
     99
     100        usb_hid_report_path_t *path = usb_hid_report_path_clone(cmp_path);
     101        if (path == NULL)
     102                return NULL;
     103
     104        list_append(&path->cpath_link, &report->collection_paths);
     105        report->collection_paths_count++;
     106
     107        return path;
    121108}
    122109
     
    474461                                    usb_hid_report_item_t, link);
    475462
     463                                link_t *tmp_link = list_prev(
     464                                    &report_item->usage_path->cpath_link,
     465                                    &report->collection_paths);
     466                                assert(tmp_link);
     467
    476468                                usb_hid_report_usage_path_t *tmp_usage_path;
    477                                 tmp_usage_path = list_get_instance(
    478                                     report_item->usage_path->cpath_link.prev,
     469                                tmp_usage_path = list_get_instance(tmp_link,
    479470                                    usb_hid_report_usage_path_t, rpath_items_link);
    480471
     
    486477
    487478                                usb_hid_report_path_free(report_item->usage_path);
    488                                 list_remove (item_link);
     479                                list_remove(item_link);
    489480
    490481                                break;
  • uspace/lib/usbhid/src/hidparser.c

    r1a37496 rf959a20f  
    493493
    494494        if (field == NULL) {
    495                 field_it = report_des->report_items.head.next;
    496         } else {
    497                 field_it = field->ritems_link.next;
    498         }
    499 
    500         while (field_it != &report_des->report_items.head) {
     495                field_it = list_first(&report_des->report_items);
     496        } else {
     497                field_it = list_next(&field->ritems_link, &report_des->report_items);
     498        }
     499
     500        while (field_it != NULL) {
    501501                field = list_get_instance(field_it, usb_hid_report_field_t,
    502502                    ritems_link);
     
    514514                        usb_hid_report_remove_last_item(field->collection_path);
    515515                }
    516                 field_it = field_it->next;
     516                field_it = list_next(field_it, &report_des->report_items);
    517517        }
    518518
     
    547547                        return 0;
    548548                } else {
    549                         report_it = report_des->reports_link.next;
     549                        report_it = list_next(&report_des->reports_link,
     550                            &report->reports);
    550551                }
    551552        } else {
    552                 report_it = report->reports.head.next;
    553         }
    554 
    555         while (report_it != &report->reports.head) {
     553                report_it = list_first(&report->reports);
     554        }
     555
     556        while (report_it != NULL) {
    556557                report_des = list_get_instance(report_it,
    557558                    usb_hid_report_description_t, reports_link);
     
    561562                }
    562563
    563                 report_it = report_it->next;
     564                report_it = list_next(report_it, &report->reports);
    564565        }
    565566
  • uspace/lib/usbhid/src/hidpath.c

    r1a37496 rf959a20f  
    250250                 * Path is prefix of the report_path
    251251                 */
    252                 report_link = report_path->items.head.next;
    253                 path_link = path->items.head.next;
    254 
    255                 while ((report_link != &report_path->items.head) &&
    256                     (path_link != &path->items.head)) {
     252                report_link = list_first(&report_path->items);
     253                path_link = list_first(&path->items);
     254
     255                while (report_link != NULL && path_link != NULL) {
    257256
    258257                        report_item = list_get_instance(report_link,
     
    268267                                return 1;
    269268                        } else {
    270                                 report_link = report_link->next;
    271                                 path_link = path_link->next;
     269                                report_link = list_next(report_link, &report_path->items);
     270                                path_link = list_next(path_link, &path->items);
    272271                        }
    273272                }
    274273
    275274                if ((((flags & USB_HID_PATH_COMPARE_BEGIN) != 0) &&
    276                     (path_link == &path->items.head)) ||
    277                     ((report_link == &report_path->items.head) &&
    278                     (path_link == &path->items.head))) {
     275                    (path_link == NULL)) ||
     276                    (report_link == NULL && path_link == NULL)) {
    279277                        return 0;
    280278                } else {
     
    287285                 * Path is suffix of report_path
    288286                 */
    289                 report_link = report_path->items.head.prev;
    290                 path_link = path->items.head.prev;
     287                report_link = list_last(&report_path->items);
     288                path_link = list_last(&path->items);
    291289
    292290                if (list_empty(&path->items)) {
     
    294292                }
    295293
    296                 while ((report_link != &report_path->items.head) &&
    297                     (path_link != &path->items.head)) {
     294                while (report_link != NULL && path_link != NULL) {
    298295                        report_item = list_get_instance(report_link,
    299296                            usb_hid_report_usage_path_t, rpath_items_link);
     
    308305                                return 1;
    309306                        } else {
    310                                 report_link = report_link->prev;
    311                                 path_link = path_link->prev;
     307                                report_link = list_prev(report_link, &report_path->items);
     308                                path_link = list_prev(path_link, &path->items);
    312309                        }
    313310                }
    314311
    315                 if (path_link == &path->items.head) {
     312                if (path_link == NULL) {
    316313                        return 0;
    317314                } else {
  • uspace/srv/devman/driver.c

    r1a37496 rf959a20f  
    435435         * that has not been passed to the driver.
    436436         */
    437         link = driver->devices.head.next;
    438         while (link != &driver->devices.head) {
     437        link = list_first(&driver->devices);
     438        while (link != NULL) {
    439439                dev = list_get_instance(link, dev_node_t, driver_devices);
    440440                fibril_rwlock_write_lock(&tree->rwlock);
     
    442442                if (dev->passed_to_driver) {
    443443                        fibril_rwlock_write_unlock(&tree->rwlock);
    444                         link = link->next;
     444                        link = list_next(link, &driver->devices);
    445445                        continue;
    446446                }
     
    484484                 * Restart the cycle to go through all devices again.
    485485                 */
    486                 link = driver->devices.head.next;
     486                link = list_first(&driver->devices);
    487487        }
    488488
  • uspace/srv/devman/match.c

    r1a37496 rf959a20f  
    6767int get_match_score(driver_t *drv, dev_node_t *dev)
    6868{
    69         link_t *drv_head = &drv->match_ids.ids.head;
    70         link_t *dev_head = &dev->pfun->match_ids.ids.head;
    71 
    72         if (list_empty(&drv->match_ids.ids) ||
    73             list_empty(&dev->pfun->match_ids.ids)) {
     69        list_t *drv_list = &drv->match_ids.ids;
     70        list_t *dev_list = &dev->pfun->match_ids.ids;
     71
     72        if (list_empty(drv_list) || list_empty(dev_list))
    7473                return 0;
    75         }
    7674
    7775        /*
     
    8078        int highest_score = 0;
    8179
    82         link_t *drv_link = drv->match_ids.ids.head.next;
    83         while (drv_link != drv_head) {
    84                 link_t *dev_link = dev_head->next;
    85                 while (dev_link != dev_head) {
    86                         match_id_t *drv_id = list_get_instance(drv_link, match_id_t, link);
    87                         match_id_t *dev_id = list_get_instance(dev_link, match_id_t, link);
    88 
     80        list_foreach(*drv_list, link, match_id_t, drv_id) {
     81                list_foreach(*dev_list, link, match_id_t, dev_id) {
    8982                        int score = compute_match_score(drv_id, dev_id);
    90                         if (score > highest_score) {
     83                        if (score > highest_score)
    9184                                highest_score = score;
    92                         }
    93 
    94                         dev_link = dev_link->next;
    9585                }
    96 
    97                 drv_link = drv_link->next;
    9886        }
    9987
  • uspace/srv/fs/exfat/exfat_idx.c

    r1a37496 rf959a20f  
    284284                link_t *lnk;
    285285                freed_t *n;
    286                 for (lnk = u->freed_list.head.next; lnk != &u->freed_list.head;
    287                     lnk = lnk->next) {
     286                for (lnk = list_first(&u->freed_list); lnk != NULL;
     287                    lnk = list_next(lnk, &u->freed_list)) {
    288288                        freed_t *f = list_get_instance(lnk, freed_t, link);
    289289                        if (f->first == index + 1) {
    290290                                f->first--;
    291                                 if (lnk->prev != &u->freed_list.head)
    292                                         try_coalesce_intervals(lnk->prev, lnk,
    293                                             lnk);
     291                                link_t *prev = list_prev(lnk, &u->freed_list);
     292                                if (prev)
     293                                        try_coalesce_intervals(prev, lnk, lnk);
    294294                                fibril_mutex_unlock(&unused_lock);
    295295                                return;
     
    297297                        if (f->last == index - 1) {
    298298                                f->last++;
    299                                 if (lnk->next != &u->freed_list.head)
    300                                         try_coalesce_intervals(lnk, lnk->next,
    301                                             lnk);
     299                                link_t *next = list_next(lnk, &u->freed_list);
     300                                if (next)
     301                                        try_coalesce_intervals(lnk, next, lnk);
    302302                                fibril_mutex_unlock(&unused_lock);
    303303                                return;
  • uspace/srv/fs/fat/fat_idx.c

    r1a37496 rf959a20f  
    284284                link_t *lnk;
    285285                freed_t *n;
    286                 for (lnk = u->freed_list.head.next; lnk != &u->freed_list.head;
    287                     lnk = lnk->next) {
     286                for (lnk = list_first(&u->freed_list); lnk != NULL;
     287                    lnk = list_next(lnk, &u->freed_list)) {
    288288                        freed_t *f = list_get_instance(lnk, freed_t, link);
    289289                        if (f->first == index + 1) {
    290290                                f->first--;
    291                                 if (lnk->prev != &u->freed_list.head)
    292                                         try_coalesce_intervals(lnk->prev, lnk,
    293                                             lnk);
     291                                link_t *prev = list_prev(lnk, &u->freed_list);
     292                                if (prev)
     293                                        try_coalesce_intervals(prev, lnk, lnk);
    294294                                fibril_mutex_unlock(&unused_lock);
    295295                                return;
     
    297297                        if (f->last == index - 1) {
    298298                                f->last++;
    299                                 if (lnk->next != &u->freed_list.head)
    300                                         try_coalesce_intervals(lnk, lnk->next,
    301                                             lnk);
     299                                link_t *next = list_next(lnk, &u->freed_list);
     300                                if (next)
     301                                        try_coalesce_intervals(lnk, next, lnk);
    302302                                fibril_mutex_unlock(&unused_lock);
    303303                                return;
  • uspace/srv/hid/compositor/compositor.c

    r1a37496 rf959a20f  
    427427
    428428                        /* For each window. */
    429                         for (link_t *link = window_list.head.prev;
    430                             link != &window_list.head; link = link->prev) {
    431 
     429                        list_foreach_rev(window_list, link, window_t, win) {
    432430                                /*
    433431                                 * Determine what part of the window intersects with the
    434432                                 * updated area of the current viewport.
    435433                                 */
    436                                 window_t *win = list_get_instance(link, window_t, link);
    437                                 if (!win->surface) {
     434                                if (!win->surface)
    438435                                        continue;
    439                                 }
     436
    440437                                sysarg_t x_dmg_win, y_dmg_win, w_dmg_win, h_dmg_win;
    441438                                surface_get_resolution(win->surface, &w_dmg_win, &h_dmg_win);
  • uspace/srv/net/tcp/ncsim.c

    r1a37496 rf959a20f  
    108108                sqe->delay -= old_qe->delay;
    109109
    110                 link = link->next;
    111                 if (link == &sim_queue.head)
    112                         link = NULL;
     110                link = list_next(link, &sim_queue);
    113111        }
    114112
  • uspace/srv/net/tcp/tqueue.c

    r1a37496 rf959a20f  
    245245void tcp_tqueue_ack_received(tcp_conn_t *conn)
    246246{
    247         link_t *cur, *next;
    248 
    249247        log_msg(LOG_DEFAULT, LVL_DEBUG, "%s: tcp_tqueue_ack_received(%p)", conn->name,
    250248            conn);
    251249
    252         cur = conn->retransmit.list.head.next;
    253 
    254         while (cur != &conn->retransmit.list.head) {
    255                 next = cur->next;
    256 
     250        list_foreach_safe(conn->retransmit.list, cur, next) {
    257251                tcp_tqueue_entry_t *tqe = list_get_instance(cur,
    258252                    tcp_tqueue_entry_t, link);
     
    277271                        tcp_tqueue_timer_set(conn);
    278272                }
    279 
    280                 cur = next;
    281273        }
    282274
Note: See TracChangeset for help on using the changeset viewer.