Changeset 111b9b9 in mainline for kernel/generic/src/proc/scheduler.c


Ignore:
Timestamp:
2023-02-11T19:13:44Z (2 years ago)
Author:
Jiří Zárevúcky <zarevucky.jiri@…>
Branches:
master, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
4777e02
Parents:
76e17d7c
git-author:
Jiří Zárevúcky <zarevucky.jiri@…> (2022-08-15 17:46:39)
git-committer:
Jiří Zárevúcky <zarevucky.jiri@…> (2023-02-11 19:13:44)
Message:

Reimplement waitq using thread_wait/wakeup

This adds a few functions to the thread API which can be
summarized as "stop running until woken up by others".
The ordering and context-switching concerns are thus yeeted
to this abstraction and waitq only deals with maintaining
the queues. Overall, this makes the control flow in waitq
much easier to navigate.

File:
1 edited

Legend:

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

    r76e17d7c r111b9b9  
    300300}
    301301
     302void scheduler(void)
     303{
     304        ipl_t ipl = interrupts_disable();
     305
     306        if (atomic_load(&haltstate))
     307                halt();
     308
     309        if (THREAD) {
     310                irq_spinlock_lock(&THREAD->lock, false);
     311        }
     312
     313        scheduler_locked(ipl);
     314}
     315
    302316/** The scheduler
    303317 *
     
    307321 *
    308322 */
    309 void scheduler(void)
    310 {
    311         volatile ipl_t ipl;
    312 
     323void scheduler_locked(ipl_t ipl)
     324{
    313325        assert(CPU != NULL);
    314326
    315         ipl = interrupts_disable();
    316 
    317         if (atomic_load(&haltstate))
    318                 halt();
    319 
    320327        if (THREAD) {
    321                 irq_spinlock_lock(&THREAD->lock, false);
    322 
    323328                /* Update thread kernel accounting */
    324329                THREAD->kcycles += get_cycle() - THREAD->last_cycle;
     
    419424                case Exiting:
    420425                        irq_spinlock_unlock(&THREAD->lock, false);
    421                         waitq_wakeup(&THREAD->join_wq, WAKEUP_CLOSE);
     426                        waitq_close(&THREAD->join_wq);
    422427
    423428                        /*
     
    434439                         */
    435440                        THREAD->priority = -1;
    436 
    437                         /*
    438                          * We need to release wq->lock which we locked in
    439                          * waitq_sleep(). Address of wq->lock is kept in
    440                          * THREAD->sleep_queue.
    441                          */
    442                         irq_spinlock_unlock(&THREAD->sleep_queue->lock, false);
    443 
    444441                        irq_spinlock_unlock(&THREAD->lock, false);
    445442                        break;
Note: See TracChangeset for help on using the changeset viewer.