Changeset 41bfc64 in mainline for kernel/generic/src/proc/scheduler.c


Ignore:
Timestamp:
2024-01-20T17:24:56Z (4 months ago)
Author:
Jiří Zárevúcky <zarevucky.jiri@…>
Branches:
master
Children:
7364e2d1
Parents:
3d84734
git-author:
Jiří Zárevúcky <zarevucky.jiri@…> (2024-01-20 16:23:31)
git-committer:
Jiří Zárevúcky <zarevucky.jiri@…> (2024-01-20 17:24:56)
Message:

Make thread→state weakly atomic so we don't need to hold thread lock

File:
1 edited

Legend:

Unmodified
Added
Removed
  • kernel/generic/src/proc/scheduler.c

    r3d84734 r41bfc64  
    313313        assert(atomic_get_unordered(&THREAD->cpu) == CPU);
    314314
    315         THREAD->state = Running;
     315        atomic_set_unordered(&THREAD->state, Running);
    316316        atomic_set_unordered(&THREAD->priority, rq_index);  /* Correct rq index */
    317317
     
    386386        irq_spinlock_lock(&thread->lock, false);
    387387
    388         assert(thread->state == Running);
     388        assert(atomic_get_unordered(&thread->state) == Running);
    389389        assert(atomic_get_unordered(&thread->cpu) == CPU);
    390390
     
    396396        }
    397397
    398         thread->state = Ready;
     398        atomic_set_unordered(&thread->state, Ready);
    399399
    400400        irq_spinlock_unlock(&thread->lock, false);
     
    409409        irq_spinlock_lock(&thread->lock, false);
    410410
    411         assert(thread->state == Sleeping || thread->state == Entering);
     411        assert(atomic_get_unordered(&thread->state) == Sleeping || atomic_get_unordered(&thread->state) == Entering);
    412412
    413413        atomic_set_unordered(&thread->priority, 0);
    414         thread->state = Ready;
     414        atomic_set_unordered(&thread->state, Ready);
    415415
    416416        /* Prefer the CPU on which the thread ran last */
     
    471471                 */
    472472                panic("tid%" PRIu64 ": unexpected state %s.",
    473                     thread->tid, thread_states[thread->state]);
     473                    thread->tid, thread_states[out_state]);
    474474                break;
    475475        }
     
    501501
    502502        irq_spinlock_lock(&THREAD->lock, false);
    503         THREAD->state = new_state;
     503
     504        atomic_set_unordered(&THREAD->state, new_state);
    504505
    505506        /* Update thread kernel accounting */
     
    809810                            thread) {
    810811                                printf("%" PRIu64 "(%s) ", thread->tid,
    811                                     thread_states[thread->state]);
     812                                    thread_states[atomic_get_unordered(&thread->state)]);
    812813                        }
    813814                        printf("\n");
Note: See TracChangeset for help on using the changeset viewer.