Browse Source

futex: Avoid unnecessary lock

It is not necessary the spin lock to protect atomic operation.

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
pull/37353/head
Flavio Ceolin 4 years ago committed by Christopher Friedt
parent
commit
f2e323f06c
  1. 5
      kernel/futex.c

5
kernel/futex.c

@ -74,13 +74,12 @@ int z_impl_k_futex_wait(struct k_futex *futex, int expected,
return -EINVAL; return -EINVAL;
} }
key = k_spin_lock(&futex_data->lock);
if (atomic_get(&futex->val) != (atomic_val_t)expected) { if (atomic_get(&futex->val) != (atomic_val_t)expected) {
k_spin_unlock(&futex_data->lock, key);
return -EAGAIN; return -EAGAIN;
} }
key = k_spin_lock(&futex_data->lock);
ret = z_pend_curr(&futex_data->lock, ret = z_pend_curr(&futex_data->lock,
key, &futex_data->wait_q, timeout); key, &futex_data->wait_q, timeout);
if (ret == -EAGAIN) { if (ret == -EAGAIN) {

Loading…
Cancel
Save