From 2ea38794876c907639971035ed29c4e59964fd7f Mon Sep 17 00:00:00 2001 From: Olivier Dion Date: Thu, 30 Mar 2023 16:09:50 -0400 Subject: [PATCH] urcu-wait: Fix wait state load/store The state of a wait node must be accessed atomically. Also, the action of busy loading until the teardown state is seen must follow a CMM_ACQUIRE semantic while storing the teardown must follow a CMM_RELEASE semantic. Change-Id: I9cd9cf4cd9ab2081551d7f33c0b1c23c3cf3942f Co-authored-by: Mathieu Desnoyers Signed-off-by: Olivier Dion Signed-off-by: Mathieu Desnoyers --- src/urcu-wait.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/urcu-wait.h b/src/urcu-wait.h index 68a42da..1fa95c3 100644 --- a/src/urcu-wait.h +++ b/src/urcu-wait.h @@ -122,7 +122,7 @@ void urcu_adaptative_wake_up(struct urcu_wait_node *wait) urcu_die(errno); } /* Allow teardown of struct urcu_wait memory. */ - uatomic_or(&wait->state, URCU_WAIT_TEARDOWN); + uatomic_or_mo(&wait->state, URCU_WAIT_TEARDOWN, CMM_RELEASE); } /* @@ -180,7 +180,7 @@ skip_futex_wait: break; caa_cpu_relax(); } - while (!(uatomic_read(&wait->state) & URCU_WAIT_TEARDOWN)) + while (!(uatomic_load(&wait->state, CMM_ACQUIRE) & URCU_WAIT_TEARDOWN)) poll(NULL, 0, 10); urcu_posix_assert(uatomic_read(&wait->state) & URCU_WAIT_TEARDOWN); } @@ -196,7 +196,7 @@ void urcu_wake_all_waiters(struct urcu_waiters *waiters) caa_container_of(iter, struct urcu_wait_node, node); /* Don't wake already running threads */ - if (wait_node->state & URCU_WAIT_RUNNING) + if (uatomic_load(&wait_node->state, CMM_RELAXED) & URCU_WAIT_RUNNING) continue; urcu_adaptative_wake_up(wait_node); } -- 2.39.5