[lttng-dev] [RFC PATCH urcu 1/3] Fix: uatomic arm32: add missing release barrier before uatomic_xchg

Mathieu Desnoyers mathieu.desnoyers at efficios.com
Mon Dec 5 17:31:11 UTC 2016


__sync_lock_test_and_set() only imply a release barrier, but
uatomic_xchg() guarantees both acquire and release barrier semantics.
Therefore, add the missing release barrier.

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers at efficios.com>
---
 include/urcu/uatomic/arm.h | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)

diff --git a/include/urcu/uatomic/arm.h b/include/urcu/uatomic/arm.h
index fd8fe6a..95f32f3 100644
--- a/include/urcu/uatomic/arm.h
+++ b/include/urcu/uatomic/arm.h
@@ -26,13 +26,27 @@
 
 #include <urcu/compiler.h>
 #include <urcu/system.h>
+#include <urcu/arch.h>
 
 #ifdef __cplusplus
 extern "C" {
 #endif
 
 /* xchg */
-#define uatomic_xchg(addr, v) __sync_lock_test_and_set(addr, v)
+
+/*
+ * Based on [1], __sync_lock_test_and_set() is not a full barrier, but
+ * instead only an acquire barrier. Given that uatomic_xchg() acts as
+ * both release and acquire barriers, we therefore need to have our own
+ * release barrier before this operation.
+ *
+ * [1] https://gcc.gnu.org/onlinedocs/gcc-4.1.0/gcc/Atomic-Builtins.html
+ */
+#define uatomic_xchg(addr, v)				\
+	({						\
+		cmm_smp_mb();				\
+		__sync_lock_test_and_set(addr, v);	\
+	})
 
 #ifdef __cplusplus
 }
-- 
2.1.4



More information about the lttng-dev mailing list