1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
|
From: Daniel Pocock <daniel@pocock.com.au>
Date: Wed, 4 Sep 2013 18:50:03 +0200
Subject: Support atomic operations on additional CPUs
---
common/c_cpp/src/c/linux/wInterlocked.h | 39 +++++++++++++++++++++++++++++++
1 file changed, 39 insertions(+)
diff --git a/common/c_cpp/src/c/linux/wInterlocked.h b/common/c_cpp/src/c/linux/wInterlocked.h
index 6ee00db..cac7374 100644
--- a/common/c_cpp/src/c/linux/wInterlocked.h
+++ b/common/c_cpp/src/c/linux/wInterlocked.h
@@ -33,6 +33,8 @@
/* Linux implementation. */
/* *************************************************** */
+#if defined(__i386__) || defined(__x86_64__)
+
/* 32-bit atomic exchange. Returns previous value. */
static __inline__ uint32_t
axchg32 (uint32_t* ptr, uint32_t newVal)
@@ -62,6 +64,43 @@ adec32 (uint32_t* ptr)
: "m" (*ptr));
}
+#else
+
+#ifdef __GNUC__
+
+/* 32-bit atomic exchange. Returns previous value. */
+static __inline__ uint32_t
+axchg32 (uint32_t* ptr, uint32_t newVal)
+{
+ /* Warning: behavior not guaranteed to be consistent
+ on all platforms. Unit tests may be required to validate
+ on each build.
+ http://gcc.gnu.org/onlinedocs/gcc-4.3.5/gcc/Atomic-Builtins.html
+ */
+ return __sync_lock_test_and_set(ptr, newVal);
+}
+
+/* 32-bit atomic increment. */
+static __inline__ void
+ainc32 (uint32_t* ptr)
+{
+ __sync_fetch_and_add(ptr, 1);
+}
+
+/* 32-bit atomic decrement. */
+static __inline__ void
+adec32 (uint32_t* ptr)
+{
+ __sync_fetch_and_sub(ptr, 1);
+}
+
+#else
+#error "Unsupported CPU / compiler combination, please implement atomic functions"
+#endif
+
+
+#endif
+
/* *************************************************** */
/* Type Defines. */
/* *************************************************** */
|