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


Ignore:
Timestamp:
2023-02-10T22:59:11Z (15 months ago)
Author:
Jiří Zárevúcky <zarevucky.jiri@…>
Branches:
master, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
11d2c983
Parents:
daadfa6
git-author:
Jiří Zárevúcky <zarevucky.jiri@…> (2023-02-10 22:53:12)
git-committer:
Jiří Zárevúcky <zarevucky.jiri@…> (2023-02-10 22:59:11)
Message:

Make thread_t reference counted

This simplifies interaction between various locks and thread
lifespan, which simplifies things. For example, threads_lock can
now simply be a mutex protecting the global it was made for, and
nothing more.

File:
1 edited

Legend:

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

    rdaadfa6 r1871118  
    389389void scheduler_separated_stack(void)
    390390{
    391         DEADLOCK_PROBE_INIT(p_joinwq);
    392391        task_t *old_task = TASK;
    393392        as_t *old_as = AS;
     
    419418
    420419                case Exiting:
    421                 repeat:
    422                         if (THREAD->detached) {
    423                                 thread_destroy(THREAD, false);
    424                         } else {
    425                                 /*
    426                                  * The thread structure is kept allocated until
    427                                  * somebody calls thread_detach() on it.
    428                                  */
    429                                 if (!irq_spinlock_trylock(&THREAD->join_wq.lock)) {
    430                                         /*
    431                                          * Avoid deadlock.
    432                                          */
    433                                         irq_spinlock_unlock(&THREAD->lock, false);
    434                                         delay(HZ);
    435                                         irq_spinlock_lock(&THREAD->lock, false);
    436                                         DEADLOCK_PROBE(p_joinwq,
    437                                             DEADLOCK_THRESHOLD);
    438                                         goto repeat;
    439                                 }
    440                                 _waitq_wakeup_unsafe(&THREAD->join_wq,
    441                                     WAKEUP_FIRST);
    442                                 irq_spinlock_unlock(&THREAD->join_wq.lock, false);
    443 
    444                                 THREAD->state = Lingering;
    445                                 irq_spinlock_unlock(&THREAD->lock, false);
    446                         }
     420                        irq_spinlock_unlock(&THREAD->lock, false);
     421                        waitq_wakeup(&THREAD->join_wq, WAKEUP_CLOSE);
     422
     423                        /*
     424                         * Release the reference CPU has for the thread.
     425                         * If there are no other references (e.g. threads calling join),
     426                         * the thread structure is deallocated.
     427                         */
     428                        thread_put(THREAD);
    447429                        break;
    448430
     
    556538        size_t average;
    557539        size_t rdy;
    558 
    559         /*
    560          * Detach kcpulb as nobody will call thread_join_timeout() on it.
    561          */
    562         thread_detach(THREAD);
    563540
    564541loop:
Note: See TracChangeset for help on using the changeset viewer.