From cf0e5b4db2f2b2651300d1598f14690f87762f10 Mon Sep 17 00:00:00 2001 From: nmushell Date: Thu, 10 Sep 2015 16:49:44 -0400 Subject: [PATCH] unix: Support atomic compare & swap xlC on AIX MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit On AIX with the native xlC compiler, the compiler supports sync compare swap and compare in two flavors: 1 __compare_and_swap 2 __compare_and_swaplp This differs from the gcc version of this function in name. The second version of this function supports 8-byte boundary for a doubleword. Therefore, the macro logic checks: if (AIX OS AND using xlC compiler) if (64bit) __compare_and_swaplp /* 64 bit version */ else __compare_and_swap endif endif Signed-off-by: Neil Mushell PR-URL: https://github.com/libuv/libuv/pull/521 Reviewed-By: Ben Noordhuis Reviewed-By: Michael Dawson Reviewed-By: Saúl Ibarra Corretgé --- src/unix/atomic-ops.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/unix/atomic-ops.h b/src/unix/atomic-ops.h index 7e4e64be..8fb157dc 100644 --- a/src/unix/atomic-ops.h +++ b/src/unix/atomic-ops.h @@ -33,6 +33,10 @@ UV_UNUSED(static int cmpxchgi(int* ptr, int oldval, int newval)) { : "r" (newval), "0" (oldval) : "memory"); return out; +#elif defined(_AIX) && defined(__xlC__) + const int out = (*(volatile int*) ptr); + __compare_and_swap(ptr, &oldval, newval); + return out; #else return __sync_val_compare_and_swap(ptr, oldval, newval); #endif @@ -46,6 +50,14 @@ UV_UNUSED(static long cmpxchgl(long* ptr, long oldval, long newval)) { : "r" (newval), "0" (oldval) : "memory"); return out; +#elif defined(_AIX) && defined(__xlC__) + const long out = (*(volatile int*) ptr); +# if defined(__64BIT__) + __compare_and_swaplp(ptr, &oldval, newval); +# else + __compare_and_swap(ptr, &oldval, newval); +# endif /* if defined(__64BIT__) */ + return out; #else return __sync_val_compare_and_swap(ptr, oldval, newval); #endif