urcu-wait: Fix wait state load/store
authorOlivier Dion <odion@efficios.com>
Thu, 30 Mar 2023 20:09:50 +0000 (16:09 -0400)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Mon, 14 Aug 2023 19:39:11 +0000 (15:39 -0400)
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 <mathieu.desnoyers@efficios.com>
Signed-off-by: Olivier Dion <odion@efficios.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
src/urcu-wait.h

index 68a42dac22c67c8df9e14608a52c05b3b109e0f7..1fa95c305dee77f944be5930b8dc7a092f66d17a 100644 (file)
@@ -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);
        }
This page took 0.028184 seconds and 4 git commands to generate.