diff options
author | Agustina Arzille <avarzille@riseup.net> | 2017-07-21 00:50:34 +0200 |
---|---|---|
committer | Richard Braun <rbraun@sceen.net> | 2017-07-21 00:50:43 +0200 |
commit | 5c2cf8fff7a1d6dc6b88615df5433ddccbbcf51f (patch) | |
tree | 4eb919999949d471204ca8489169351f1390ccb5 /kern/thread.c | |
parent | 4278f99adcbcfbd52904c0d8809184afe091c958 (diff) |
kern/mutex: new adaptive spinning mutex implementation
Diffstat (limited to 'kern/thread.c')
-rw-r--r-- | kern/thread.c | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/kern/thread.c b/kern/thread.c index e6875586..7ce22fb7 100644 --- a/kern/thread.c +++ b/kern/thread.c @@ -551,7 +551,7 @@ thread_runq_get_next(struct thread_runq *runq) thread = thread_sched_ops[i].get_next(runq); if (thread != NULL) { - runq->current = thread; + atomic_store(&runq->current, thread, ATOMIC_RELAXED); return thread; } } @@ -571,7 +571,7 @@ thread_runq_set_next(struct thread_runq *runq, struct thread *thread) ops->set_next(runq, thread); } - runq->current = thread; + atomic_store(&runq->current, thread, ATOMIC_RELAXED); } static void @@ -2736,3 +2736,14 @@ thread_key_create(unsigned int *keyp, thread_dtor_fn_t dtor) thread_dtors[key] = dtor; *keyp = key; } + +bool +thread_is_running(const struct thread *thread) +{ + const struct thread_runq *runq; + + runq = thread->runq; + + return (runq != NULL) + && (atomic_load(&runq->current, ATOMIC_RELAXED) == thread); +} |