2017-12-18 15:41:03 +08:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2017 Intel Corporation
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <kernel.h>
|
2018-04-06 01:11:15 +08:00
|
|
|
#include <posix/pthread.h>
|
|
|
|
#include <ksched.h>
|
|
|
|
#include <wait_q.h>
|
2018-01-26 07:24:15 +08:00
|
|
|
#include <kswap.h>
|
2017-12-18 15:41:03 +08:00
|
|
|
|
|
|
|
void ready_one_thread(_wait_q_t *wq);
|
|
|
|
|
|
|
|
int pthread_barrier_wait(pthread_barrier_t *b)
|
|
|
|
{
|
|
|
|
int key = irq_lock();
|
|
|
|
|
|
|
|
b->count++;
|
|
|
|
|
|
|
|
if (b->count >= b->max) {
|
|
|
|
b->count = 0;
|
|
|
|
|
|
|
|
while (!sys_dlist_is_empty(&b->wait_q)) {
|
|
|
|
ready_one_thread(&b->wait_q);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
_pend_current_thread(&b->wait_q, K_FOREVER);
|
|
|
|
}
|
|
|
|
|
kernel: Scheduler refactoring: use _reschedule_*() always
There was a somewhat promiscuous pattern in the kernel where IPC
mechanisms would do something that might effect the current thread
choice, then check _must_switch_threads() (or occasionally
__must_switch_threads -- don't ask, the distinction is being replaced
by real English words), sometimes _is_in_isr() (but not always, even
in contexts where that looks like it would be a mistake), and then
call _Swap() if everything is OK, otherwise releasing the irq_lock().
Sometimes this was done directly, sometimes via the inverted test,
sometimes (poll, heh) by doing the test when the thread state was
modified and then needlessly passing the result up the call stack to
the point of the _Swap().
And some places were just calling _reschedule_threads(), which did all
this already.
Unify all this madness. The old _reschedule_threads() function has
split into two variants: _reschedule_yield() and
_reschedule_noyield(). The latter is the "normal" one that respects
the cooperative priority of the current thread (i.e. it won't switch
out even if there is a higher priority thread ready -- the current
thread has to pend itself first), the former is used in the handful of
places where code was doing a swap unconditionally, just to preserve
precise behavior across the refactor. I'm not at all convinced it
should exist...
Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2018-03-27 01:54:40 +08:00
|
|
|
return _reschedule_noyield(key);
|
2017-12-18 15:41:03 +08:00
|
|
|
}
|