Changeset 11d2c983 in mainline


Ignore:
Timestamp:
2023-02-11T18:35:15Z (23 months ago)
Author:
Jiří Zárevúcky <zarevucky.jiri@…>
Branches:
master, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
76e17d7c
Parents:
1871118
git-author:
Jiří Zárevúcky <zarevucky.jiri@…> (2023-02-07 18:02:51)
git-committer:
Jiří Zárevúcky <zarevucky.jiri@…> (2023-02-11 18:35:15)
Message:

Reorganize locking in thread_destroy()

Location:
kernel/generic
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • kernel/generic/include/proc/task.h

    r1871118 r11d2c983  
    8989        atomic_size_t refcount;
    9090        /** Number of threads that haven't exited yet. */
     91        // TODO: remove
    9192        atomic_size_t lifecount;
    9293
  • kernel/generic/src/proc/thread.c

    r1871118 r11d2c983  
    398398 * Detach thread from all queues, cpus etc. and destroy it.
    399399 *
    400  * @param thread  Thread to be destroyed.
    401  * @param irq_res Indicate whether it should unlock thread->lock
    402  *                in interrupts-restore mode.
     400 * @param obj  Thread to be destroyed.
    403401 *
    404402 */
     
    407405        thread_t *thread = (thread_t *) obj;
    408406
    409         irq_spinlock_lock(&thread->lock, true);
     407        assert_link_not_used(&thread->rq_link);
     408        assert_link_not_used(&thread->wq_link);
     409
     410        assert(thread->task);
     411
     412        ipl_t ipl = interrupts_disable();
     413
     414        /* Remove thread from task's list. */
     415        irq_spinlock_lock(&thread->task->lock, false);
     416        list_remove(&thread->th_link);
     417        irq_spinlock_unlock(&thread->task->lock, false);
     418
     419        /* Remove thread from global list. */
     420        irq_spinlock_lock(&threads_lock, false);
     421        odict_remove(&thread->lthreads);
     422        irq_spinlock_unlock(&threads_lock, false);
     423
     424        /* Clear cpu->fpu_owner if set to this thread. */
     425        irq_spinlock_lock(&thread->lock, false);
     426
    410427        assert((thread->state == Exiting) || (thread->state == Lingering));
    411         assert(thread->task);
    412428        assert(thread->cpu);
    413429
     
    417433        irq_spinlock_unlock(&thread->cpu->lock, false);
    418434
    419         irq_spinlock_pass(&thread->lock, &threads_lock);
    420 
    421         odict_remove(&thread->lthreads);
    422 
    423         irq_spinlock_pass(&threads_lock, &thread->task->lock);
    424 
    425         /*
    426          * Detach from the containing task.
    427          */
    428         list_remove(&thread->th_link);
    429         irq_spinlock_unlock(&thread->task->lock, true);
     435        irq_spinlock_unlock(&thread->lock, false);
     436
     437        interrupts_restore(ipl);
    430438
    431439        /*
     
    433441         */
    434442        task_release(thread->task);
     443        thread->task = NULL;
     444
    435445        slab_free(thread_cache, thread);
    436446}
Note: See TracChangeset for help on using the changeset viewer.