Ignore:
Timestamp:
2023-02-10T22:59:11Z (2 years 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/udebug/udebug_ops.c

    rdaadfa6 r1871118  
    8383        mutex_lock(&TASK->udebug.lock);
    8484
    85         /* thread_exists() must be called with threads_lock held */
    86         irq_spinlock_lock(&threads_lock, true);
    87 
    88         if (!thread_exists(thread)) {
    89                 irq_spinlock_unlock(&threads_lock, true);
     85        thread = thread_try_get(thread);
     86
     87        if (!thread) {
    9088                mutex_unlock(&TASK->udebug.lock);
    9189                return ENOENT;
    9290        }
    9391
    94         /* thread->lock is enough to ensure the thread's existence */
    95         irq_spinlock_exchange(&threads_lock, &thread->lock);
     92        irq_spinlock_lock(&thread->lock, true);
    9693
    9794        /* Verify that 'thread' is a userspace thread. */
     
    111108        }
    112109
    113         /*
    114          * Since the thread has active == true, TASK->udebug.lock
    115          * is enough to ensure its existence and that active remains
    116          * true.
    117          *
    118          */
    119         irq_spinlock_unlock(&thread->lock, true);
    120 
    121         /* Only mutex TASK->udebug.lock left. */
    122 
    123110        /* Now verify that the thread belongs to the current task. */
    124111        if (thread->task != TASK) {
    125112                /* No such thread belonging this task */
     113                irq_spinlock_unlock(&thread->lock, true);
    126114                mutex_unlock(&TASK->udebug.lock);
    127115                return ENOENT;
    128116        }
     117
     118        irq_spinlock_unlock(&thread->lock, true);
     119
     120        /* Only mutex TASK->udebug.lock left. */
    129121
    130122        /*
     
    153145{
    154146        mutex_unlock(&thread->udebug.lock);
     147
     148        /* Drop reference from _thread_op_begin() */
     149        thread_put(thread);
    155150}
    156151
Note: See TracChangeset for help on using the changeset viewer.