Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • kernel/generic/src/udebug/udebug_ops.c

    rdfa4be62 rd1582b50  
    5151#include <udebug/udebug.h>
    5252#include <udebug/udebug_ops.h>
    53 #include <memw.h>
     53#include <mem.h>
    5454#include <stdlib.h>
    5555
     
    8383        mutex_lock(&TASK->udebug.lock);
    8484
    85         thread = thread_try_get(thread);
    86 
    87         if (!thread) {
     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);
    8890                mutex_unlock(&TASK->udebug.lock);
    8991                return ENOENT;
    9092        }
     93
     94        /* thread->lock is enough to ensure the thread's existence */
     95        irq_spinlock_exchange(&threads_lock, &thread->lock);
    9196
    9297        /* Verify that 'thread' is a userspace thread. */
    9398        if (!thread->uspace) {
     99                /* It's not, deny its existence */
     100                irq_spinlock_unlock(&thread->lock, true);
     101                mutex_unlock(&TASK->udebug.lock);
     102                return ENOENT;
     103        }
     104
     105        /* Verify debugging state. */
     106        if (thread->udebug.active != true) {
     107                /* Not in debugging session or undesired GO state */
     108                irq_spinlock_unlock(&thread->lock, true);
     109                mutex_unlock(&TASK->udebug.lock);
     110                return ENOENT;
     111        }
     112
     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
     123        /* Now verify that the thread belongs to the current task. */
     124        if (thread->task != TASK) {
     125                /* No such thread belonging this task */
    94126                mutex_unlock(&TASK->udebug.lock);
    95127                return ENOENT;
     
    103135        mutex_lock(&thread->udebug.lock);
    104136
    105         /* Verify debugging state. */
    106         if (thread->udebug.active != true) {
    107                 /* Not in debugging session or undesired GO state */
    108                 mutex_unlock(&thread->udebug.lock);
    109                 mutex_unlock(&TASK->udebug.lock);
    110                 return ENOENT;
    111         }
    112 
    113         /* Now verify that the thread belongs to the current task. */
    114         if (thread->task != TASK) {
    115                 /* No such thread belonging this task */
    116                 mutex_unlock(&thread->udebug.lock);
    117                 mutex_unlock(&TASK->udebug.lock);
    118                 return ENOENT;
    119         }
    120 
    121137        /* The big task mutex is no longer needed. */
    122138        mutex_unlock(&TASK->udebug.lock);
     
    137153{
    138154        mutex_unlock(&thread->udebug.lock);
    139 
    140         /* Drop reference from _thread_op_begin() */
    141         thread_put(thread);
    142155}
    143156
     
    268281         *
    269282         */
    270         waitq_wake_all(&thread->udebug.go_wq);
     283        waitq_wakeup(&thread->udebug.go_wq, WAKEUP_FIRST);
    271284
    272285        _thread_op_end(thread);
     
    380393        /* FIXME: make sure the thread isn't past debug shutdown... */
    381394        list_foreach(TASK->threads, th_link, thread_t, thread) {
     395                irq_spinlock_lock(&thread->lock, false);
    382396                bool uspace = thread->uspace;
     397                irq_spinlock_unlock(&thread->lock, false);
    383398
    384399                /* Not interested in kernel threads. */
Note: See TracChangeset for help on using the changeset viewer.