aix: add atomic support
authorDerrick Brashear <shadow@your-file-system.com>
Mon, 10 Sep 2012 18:43:08 +0000 (14:43 -0400)
committerDerrick Brashear <shadow@your-file-system.com>
Mon, 10 Sep 2012 20:24:39 +0000 (13:24 -0700)
aix has an atomic facility. add support for it.

Change-Id: Iaf1305fbafe1c0d7f0d22f14babfbea382c0b32d
Reviewed-on: http://gerrit.openafs.org/8076
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Simon Wilkinson <simonxwilkinson@gmail.com>
Reviewed-by: Derrick Brashear <shadow@your-file-system.com>

src/rx/rx_atomic.h

index 51e2f76..0fcc429 100644 (file)
@@ -77,6 +77,58 @@ rx_atomic_sub(rx_atomic_t *atomic, int change) {
     InterlockedExchangeAdd(&atomic->var, 0 - change);
 }
 
+#elif defined(AFS_AIX61_ENV) || defined(AFS_USR_AIX61_ENV)
+#include <sys/atomic_op.h>
+
+typedef struct {
+   volatile int var;
+} rx_atomic_t;
+
+static_inline void
+rx_atomic_set(rx_atomic_t *atomic, int val) {
+    atomic->var = val;
+}
+
+static_inline int
+rx_atomic_read(rx_atomic_t *atomic) {
+    return atomic->var;
+}
+
+static_inline void
+rx_atomic_inc(rx_atomic_t *atomic) {
+    fetch_and_add(&atomic->var, 1);
+}
+
+static_inline int
+rx_atomic_inc_and_read(rx_atomic_t *atomic) {
+    return (fetch_and_add(&atomic->var, 1) + 1);
+}
+
+static_inline void
+rx_atomic_add(rx_atomic_t *atomic, int change) {
+    fetch_and_add(&atomic->var, change);
+}
+
+static_inline int
+rx_atomic_add_and_read(rx_atomic_t *atomic, int change) {
+    return (fetch_and_add(&atomic->var, change) + change);
+}
+
+static_inline void
+rx_atomic_dec(rx_atomic_t *atomic) {
+    fetch_and_add(&atomic->var, -1);
+}
+
+static_inline int
+rx_atomic_dec_and_read(rx_atomic_t *atomic) {
+    return (fetch_and_add(&atomic->var, -1) - 1);
+}
+
+static_inline void
+rx_atomic_sub(rx_atomic_t *atomic, int change) {
+    fetch_and_add(&atomic->var, -change);
+}
+
 #elif defined(AFS_DARWIN80_ENV) || defined(AFS_USR_DARWIN80_ENV)
 
 #include <libkern/OSAtomic.h>