From 8a4b2e8cf2f5675b09f0cb1e1961e58e5582f34a Mon Sep 17 00:00:00 2001 From: Andy Ross Date: Wed, 11 Apr 2018 08:21:26 -0700 Subject: [PATCH] kernel, posix: Move ready_one_thread() to scheduler The POSIX layer had a simple ready_one_thread() utility. Move this to the scheduler API (with a prepended underscore -- it's an internal API) so that it can be synchronized along with the rest of the scheduler. Signed-off-by: Andy Ross --- kernel/include/ksched.h | 8 ++++++++ lib/posix/pthread_barrier.c | 4 +--- lib/posix/pthread_common.c | 9 --------- lib/posix/pthread_cond.c | 8 +++----- 4 files changed, 12 insertions(+), 17 deletions(-) diff --git a/kernel/include/ksched.h b/kernel/include/ksched.h index e0b38227e78..63904736c05 100644 --- a/kernel/include/ksched.h +++ b/kernel/include/ksched.h @@ -509,6 +509,14 @@ static inline struct k_thread *_unpend1_no_timeout(_wait_q_t *wait_q) return thread; } +static inline void _ready_one_thread(_wait_q_t *wq) +{ + struct k_thread *th = _unpend_first_thread(wq); + + if (th) { + _ready_thread(th); + } +} #ifdef CONFIG_USERSPACE /** diff --git a/lib/posix/pthread_barrier.c b/lib/posix/pthread_barrier.c index 920c3c7eecf..fbd1b2f52f9 100644 --- a/lib/posix/pthread_barrier.c +++ b/lib/posix/pthread_barrier.c @@ -9,8 +9,6 @@ #include #include -void ready_one_thread(_wait_q_t *wq); - int pthread_barrier_wait(pthread_barrier_t *b) { int key = irq_lock(); @@ -21,7 +19,7 @@ int pthread_barrier_wait(pthread_barrier_t *b) b->count = 0; while (!sys_dlist_is_empty(&b->wait_q)) { - ready_one_thread(&b->wait_q); + _ready_one_thread(&b->wait_q); } return _reschedule(key); } else { diff --git a/lib/posix/pthread_common.c b/lib/posix/pthread_common.c index 52766bab9ba..5c9238ee5cf 100644 --- a/lib/posix/pthread_common.c +++ b/lib/posix/pthread_common.c @@ -10,15 +10,6 @@ #include #include -void ready_one_thread(_wait_q_t *wq) -{ - struct k_thread *th = _unpend_first_thread(wq); - - if (th) { - _ready_thread(th); - } -} - s64_t timespec_to_timeoutms(const struct timespec *abstime) { s64_t milli_secs; diff --git a/lib/posix/pthread_cond.c b/lib/posix/pthread_cond.c index 7999bd800b6..55376323d37 100644 --- a/lib/posix/pthread_cond.c +++ b/lib/posix/pthread_cond.c @@ -9,8 +9,6 @@ #include #include -void ready_one_thread(_wait_q_t *wq); - static int cond_wait(pthread_cond_t *cv, pthread_mutex_t *mut, int timeout) { __ASSERT(mut->sem->count == 0, ""); @@ -18,7 +16,7 @@ static int cond_wait(pthread_cond_t *cv, pthread_mutex_t *mut, int timeout) int ret, key = irq_lock(); mut->sem->count = 1; - ready_one_thread(&mut->sem->wait_q); + _ready_one_thread(&mut->sem->wait_q); ret = _pend_current_thread(key, &cv->wait_q, timeout); /* FIXME: this extra lock (and the potential context switch it @@ -49,7 +47,7 @@ int pthread_cond_signal(pthread_cond_t *cv) { int key = irq_lock(); - ready_one_thread(&cv->wait_q); + _ready_one_thread(&cv->wait_q); _reschedule(key); return 0; @@ -60,7 +58,7 @@ int pthread_cond_broadcast(pthread_cond_t *cv) int key = irq_lock(); while (!sys_dlist_is_empty(&cv->wait_q)) { - ready_one_thread(&cv->wait_q); + _ready_one_thread(&cv->wait_q); } _reschedule(key);