kernel: Fix two k_condvar_wait() issues
1. When the timeout is K_NO_WAIT, the thread should not be added to the wait queue as that would otherwise cause to the thread to wait until the next tick (which is not a no-wait situation). 2. Threads that were added to the wait queue AND did not receive a signal before timing out should not lock the supplied mutex. Signed-off-by: Peter Mitsis <peter.mitsis@intel.com>
This commit is contained in:
committed by
Fabio Baltieri
parent
c5bc58e3bd
commit
924874baef
@@ -115,15 +115,23 @@ int z_impl_k_condvar_wait(struct k_condvar *condvar, struct k_mutex *mutex,
|
||||
k_timeout_t timeout)
|
||||
{
|
||||
k_spinlock_key_t key;
|
||||
int ret;
|
||||
int ret = -EAGAIN;
|
||||
|
||||
SYS_PORT_TRACING_OBJ_FUNC_ENTER(k_condvar, wait, condvar, timeout);
|
||||
|
||||
if (unlikely(K_TIMEOUT_EQ(timeout, K_NO_WAIT))) {
|
||||
k_mutex_unlock(mutex);
|
||||
SYS_PORT_TRACING_OBJ_FUNC_EXIT(k_condvar, wait, condvar, timeout, ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
key = k_spin_lock(&lock);
|
||||
k_mutex_unlock(mutex);
|
||||
|
||||
ret = z_pend_curr(&lock, key, &condvar->wait_q, timeout);
|
||||
k_mutex_lock(mutex, K_FOREVER);
|
||||
if (ret == 0) {
|
||||
k_mutex_lock(mutex, K_FOREVER);
|
||||
}
|
||||
|
||||
SYS_PORT_TRACING_OBJ_FUNC_EXIT(k_condvar, wait, condvar, timeout, ret);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user