Changeset 583c2a3 in mainline


Ignore:
Timestamp:
2020-07-06T22:58:19Z (4 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
37d4c91, ee2f0beb
Parents:
762f989
Message:

Avoid most cases of direct used of list_t.prev/next in kernel

Location:
kernel/generic/src
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • kernel/generic/src/console/kconsole.c

    r762f989 r583c2a3  
    172172
    173173        if (*startpos == NULL)
    174                 *startpos = cmd_list.head.next;
    175 
    176         for (; *startpos != &cmd_list.head; *startpos = (*startpos)->next) {
     174                *startpos = list_first(&cmd_list);
     175
     176        for (; *startpos != NULL; *startpos = list_next(*startpos, &cmd_list)) {
    177177                cmd_info_t *hlp = list_get_instance(*startpos, cmd_info_t, link);
    178178
     
    182182
    183183                if (str_lcmp(curname, name, namelen) == 0) {
    184                         *startpos = (*startpos)->next;
     184                        *startpos = list_next(*startpos, &cmd_list);
    185185                        if (h)
    186186                                *h = hlp->description;
  • kernel/generic/src/mm/slab.c

    r762f989 r583c2a3  
    837837                irq_spinlock_lock(&slab_cache_lock, true);
    838838
    839                 link_t *cur = slab_cache_list.head.next;
     839                link_t *cur = list_first(&slab_cache_list);
    840840                size_t i = 0;
    841                 while (i < skip && cur != &slab_cache_list.head) {
     841                while (i < skip && cur != NULL) {
    842842                        i++;
    843                         cur = cur->next;
     843                        cur = list_next(cur, &slab_cache_list);
    844844                }
    845845
    846                 if (cur == &slab_cache_list.head) {
     846                if (cur == NULL) {
    847847                        irq_spinlock_unlock(&slab_cache_lock, true);
    848848                        break;
  • kernel/generic/src/proc/scheduler.c

    r762f989 r583c2a3  
    610610
    611611                        /* Search rq from the back */
    612                         link_t *link = cpu->rq[rq].rq.head.prev;
    613 
    614                         while (link != &(cpu->rq[rq].rq.head)) {
     612                        link_t *link = list_last(&cpu->rq[rq].rq);
     613
     614                        while (link != NULL) {
    615615                                thread = (thread_t *) list_get_instance(link,
    616616                                    thread_t, rq_link);
     
    644644                                irq_spinlock_unlock(&thread->lock, false);
    645645
    646                                 link = link->prev;
     646                                link = list_prev(link, &cpu->rq[rq].rq);
    647647                                thread = NULL;
    648648                        }
  • kernel/generic/src/time/timeout.c

    r762f989 r583c2a3  
    118118        uint64_t sum = 0;
    119119        timeout_t *target = NULL;
    120         link_t *cur;
    121         for (cur = CPU->timeout_active_list.head.next;
    122             cur != &CPU->timeout_active_list.head; cur = cur->next) {
     120        link_t *cur, *prev;
     121        prev = NULL;
     122        for (cur = list_first(&CPU->timeout_active_list);
     123            cur != NULL; cur = list_next(cur, &CPU->timeout_active_list)) {
    123124                target = list_get_instance(cur, timeout_t, link);
    124125                irq_spinlock_lock(&target->lock, false);
     
    131132                sum += target->ticks;
    132133                irq_spinlock_unlock(&target->lock, false);
    133         }
    134 
    135         /* Avoid using cur->prev directly */
    136         link_t *prev = cur->prev;
    137         list_insert_after(&timeout->link, prev);
     134                prev = cur;
     135        }
     136
     137        if (prev == NULL)
     138                list_prepend(&timeout->link, &CPU->timeout_active_list);
     139        else
     140                list_insert_after(&timeout->link, prev);
    138141
    139142        /*
     
    146149         * Decrease ticks of timeout's immediate succesor by timeout->ticks.
    147150         */
    148         if (cur != &CPU->timeout_active_list.head) {
     151        if (cur != NULL) {
    149152                irq_spinlock_lock(&target->lock, false);
    150153                target->ticks -= timeout->ticks;
     
    187190         */
    188191
    189         link_t *cur = timeout->link.next;
    190         if (cur != &timeout->cpu->timeout_active_list.head) {
     192        link_t *cur = list_next(&timeout->link,
     193            &timeout->cpu->timeout_active_list);
     194        if (cur != NULL) {
    191195                timeout_t *tmp = list_get_instance(cur, timeout_t, link);
    192196                irq_spinlock_lock(&tmp->lock, false);
Note: See TracChangeset for help on using the changeset viewer.