From f2e323f06ccafde76377bad46c9341a8eb68aa5a Mon Sep 17 00:00:00 2001 From: Flavio Ceolin Date: Thu, 8 Jul 2021 17:13:29 -0700 Subject: [PATCH] futex: Avoid unnecessary lock It is not necessary the spin lock to protect atomic operation. Signed-off-by: Flavio Ceolin --- kernel/futex.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/kernel/futex.c b/kernel/futex.c index 8dab1ab07c4..6c3aaf5e8cf 100644 --- a/kernel/futex.c +++ b/kernel/futex.c @@ -74,13 +74,12 @@ int z_impl_k_futex_wait(struct k_futex *futex, int expected, return -EINVAL; } - key = k_spin_lock(&futex_data->lock); - if (atomic_get(&futex->val) != (atomic_val_t)expected) { - k_spin_unlock(&futex_data->lock, key); return -EAGAIN; } + key = k_spin_lock(&futex_data->lock); + ret = z_pend_curr(&futex_data->lock, key, &futex_data->wait_q, timeout); if (ret == -EAGAIN) {