Changeset 583c2a3 in mainline for kernel/generic/src/time/timeout.c


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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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.