From 5c2cf8fff7a1d6dc6b88615df5433ddccbbcf51f Mon Sep 17 00:00:00 2001 From: Agustina Arzille Date: Fri, 21 Jul 2017 00:50:34 +0200 Subject: kern/mutex: new adaptive spinning mutex implementation --- kern/thread.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'kern/thread.c') 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); +} -- cgit v1.2.3