diff mbox

[1/3] NPTL/ARC: implement __arch_exchange_32_acq using native EX

Message ID 1478565100-23924-2-git-send-email-vgupta@synopsys.com
State New
Headers show

Commit Message

Vineet Gupta Nov. 8, 2016, 12:31 a.m. UTC
ARC EX instruction maps directly to this primitive, thus helps elide the
llock/scond based retry loop where possible.

Signed-off-by: Vineet Gupta <vgupta@synopsys.com>
---
 libc/sysdeps/linux/arc/bits/atomic.h | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)
diff mbox

Patch

diff --git a/libc/sysdeps/linux/arc/bits/atomic.h b/libc/sysdeps/linux/arc/bits/atomic.h
index 1fdc83f70f6b..48f37879c5c4 100644
--- a/libc/sysdeps/linux/arc/bits/atomic.h
+++ b/libc/sysdeps/linux/arc/bits/atomic.h
@@ -58,3 +58,27 @@  void __arc_link_error (void);
 
 #define __arch_compare_and_exchange_val_64_acq(mem, newval, oldval) \
   ({ __arc_link_error (); oldval; })
+
+/* Store NEWVALUE in *MEM and return the old value.
+   Atomic EX is present in all configurations
+ */
+
+#define __arch_exchange_32_acq(mem, newval)				\
+  ({									\
+	__typeof__(*(mem)) val = newval;				\
+									\
+	__asm__ __volatile__(						\
+	"ex %0, [%1]"							\
+	: "+r" (val)							\
+	: "r" (mem)							\
+	: "memory" );							\
+									\
+	val;								\
+  })
+
+#define atomic_exchange_acq(mem, newval)				\
+  ({									\
+	if (sizeof(*(mem)) != 4)					\
+		abort();						\
+	__arch_exchange_32_acq(mem, newval);				\
+  })