kernel/sem: Fix SMP race

This had the same race that queue did: you have to be 100% done with
state management before calling z_ready_thread(), because another CPU
can pick up the thread before the return value was set.

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
This commit is contained in:
Andy Ross 2020-01-23 12:55:04 -08:00 committed by Anas Nashif
commit b8ff63e3c7

View file

@ -113,8 +113,8 @@ void z_impl_k_sem_give(struct k_sem *sem)
sys_trace_void(SYS_TRACE_ID_SEMA_GIVE);
if (thread != NULL) {
z_ready_thread(thread);
arch_thread_return_value_set(thread, 0);
z_ready_thread(thread);
} else {
sem->count += (sem->count != sem->limit) ? 1U : 0U;
handle_poll_events(sem);