Changeset 41bfc64 in mainline for kernel/generic/src/proc/thread.c


Ignore:
Timestamp:
2024-01-20T17:24:56Z (12 months ago)
Author:
Jiří Zárevúcky <zarevucky.jiri@…>
Branches:
master
Children:
7364e2d1
Parents:
3d84734
git-author:
Jiří Zárevúcky <zarevucky.jiri@…> (2024-01-20 16:23:31)
git-committer:
Jiří Zárevúcky <zarevucky.jiri@…> (2024-01-20 17:24:56)
Message:

Make thread→state weakly atomic so we don't need to hold thread lock

File:
1 edited

Legend:

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

    r3d84734 r41bfc64  
    209209void thread_start(thread_t *thread)
    210210{
    211         assert(thread->state == Entering);
     211        assert(atomic_get_unordered(&thread->state) == Entering);
    212212        thread_requeue_sleeping(thread_ref(thread));
    213213}
     
    269269
    270270        thread->nomigrate = 0;
    271         thread->state = Entering;
     271        atomic_init(&thread->state, Entering);
    272272
    273273        atomic_init(&thread->sleep_queue, NULL);
     
    339339        irq_spinlock_unlock(&thread->task->lock, false);
    340340
    341         assert((thread->state == Exiting) || (thread->state == Lingering));
     341        assert((atomic_get_unordered(&thread->state) == Exiting) || (atomic_get_unordered(&thread->state) == Lingering));
    342342
    343343        /* Clear cpu->fpu_owner if set to this thread. */
     
    637637                return EINVAL;
    638638
    639         irq_spinlock_lock(&thread->lock, true);
    640         state_t state = thread->state;
    641         irq_spinlock_unlock(&thread->lock, true);
     639        state_t state = atomic_get_unordered(&thread->state);
    642640
    643641        errno_t rc = EOK;
     
    686684        order_suffix(thread->ucycles, &ucycles, &usuffix);
    687685        order_suffix(thread->kcycles, &kcycles, &ksuffix);
     686
     687        state_t state = atomic_get_unordered(&thread->state);
    688688
    689689        char *name;
     
    699699        else
    700700                printf("%-8" PRIu64 " %-14s %p %-8s %p %-5" PRIu32 "\n",
    701                     thread->tid, name, thread, thread_states[thread->state],
     701                    thread->tid, name, thread, thread_states[state],
    702702                    thread->task, thread->task->container);
    703703
     
    709709                        printf("none ");
    710710
    711                 if (thread->state == Sleeping) {
     711                if (state == Sleeping) {
    712712                        printf(" %p", thread->sleep_queue);
    713713                }
     
    914914                printf("Scheduling thread stack trace.\n");
    915915                thread->btrace = true;
    916                 if (thread->state == Sleeping)
     916                if (atomic_get_unordered(&thread->state) == Sleeping)
    917917                        sleeping = true;
    918918        } else
Note: See TracChangeset for help on using the changeset viewer.