You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by mt...@apache.org on 2011/06/25 13:59:50 UTC

svn commit: r1139529 - in /commons/sandbox/runtime/trunk/src/main/native/os/unix: arch_sync.h atomic.c

Author: mturk
Date: Sat Jun 25 11:59:50 2011
New Revision: 1139529

URL: http://svn.apache.org/viewvc?rev=1139529&view=rev
Log:
Use inlines for gcc builtin atomic operations

Modified:
    commons/sandbox/runtime/trunk/src/main/native/os/unix/arch_sync.h
    commons/sandbox/runtime/trunk/src/main/native/os/unix/atomic.c

Modified: commons/sandbox/runtime/trunk/src/main/native/os/unix/arch_sync.h
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/unix/arch_sync.h?rev=1139529&r1=1139528&r2=1139529&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/unix/arch_sync.h (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/unix/arch_sync.h Sat Jun 25 11:59:50 2011
@@ -28,7 +28,7 @@
 #  define USE_ATOMICS_WRAPPER     0
 #  define USE_BUILTIN_ATOMICS     1
 # else
-#  define USE_ATOMICS_WRAPPER     1
+#  define USE_ATOMICS_WRAPPER     0
 #  define USE_BUILTIN_ATOMICS     0
 # endif
 # define  _PR_COMPILER_FENCE()    __asm__ __volatile__("" : : : "memory")
@@ -44,6 +44,55 @@
 #  endif
 #  define _PR_RWMEMORY_FENCE()    __asm__ __volatile__(__mfence : : : "memory")
 # endif
+# if USE_BUILTIN_ATOMICS
+ACR_INLINE(void)  AcrCpuFence()
+{
+    _PR_COMPILER_FENCE();
+}
+
+ACR_INLINE(void)  AcrMemoryFence()
+{
+    _PR_RWMEMORY_FENCE();
+}
+
+ACR_INLINE(int) AcrAtomic32Inc(volatile acr_atomic32_t *val)
+{
+    return (int)__sync_add_and_fetch(val, 1);
+}
+
+ACR_INLINE(int) AcrAtomic32Dec(volatile acr_atomic32_t *val)
+{
+    return (int)__sync_sub_and_fetch(val, 1);
+}
+
+ACR_INLINE(int) AcrAtomic32Cas(volatile acr_atomic32_t *val, int cmp, int set)
+{
+    return (int)__sync_val_compare_and_swap(val, cmp, set);
+}
+
+ACR_INLINE(void *) AcrAtomic32CasPtr(void * volatile *val, const void *cmp, void *set)
+{
+    return (void *)__sync_val_compare_and_swap(val, cmp, set);
+}
+
+ACR_INLINE(int) AcrAtomic32Set(volatile acr_atomic32_t *val, int num)
+{
+    __sync_synchronize();
+    return (int)__sync_lock_test_and_set(val, num);
+}
+
+ACR_INLINE(void *) AcrAtomic32SetPtr(void * volatile *val, void *set)
+{
+    __sync_synchronize();
+    return (void *)__sync_lock_test_and_set(val, set);
+}
+
+ACR_INLINE(int) AcrAtomic32Equ(volatile acr_atomic32_t *val, int num)
+{
+    return __sync_bool_compare_and_swap(val, num, num);
+}
+
+# endif
 #else
 # if defined(_SOLARIS)
 #  define USE_BUILTIN_ATOMICS     1
@@ -51,10 +100,7 @@
 #  define _PR_COMPILER_FENCE()    membar_consumer()
 #  define _PR_RWMEMORY_FENCE()    do { membar_producer(); membar_consumer(); } while (0)
 # else
-#  define USE_BUILTIN_ATOMICS     0
-#  define USE_ATOMICS_WRAPPER     1
-#  define _PR_COMPILER_FENCE()   (void)0
-#  define _PR_RWMEMORY_FENCE()   (void)0
+#  error "Atomic operations not implemented for this platform!"
 # endif
 #endif
 

Modified: commons/sandbox/runtime/trunk/src/main/native/os/unix/atomic.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/unix/atomic.c?rev=1139529&r1=1139528&r2=1139529&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/unix/atomic.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/unix/atomic.c Sat Jun 25 11:59:50 2011
@@ -18,19 +18,9 @@
 #include "arch_sync.h"
 
 
-#if USE_ATOMICS_WRAPPER
+#if USE_BUILTIN_ATOMICS
 UNUSED_SOURCE_FILE(atomic);
 #else
-# if defined(__GNUC__)
-#  if USE_BUILTIN_ATOMICS
-#   define GCC_BUILTIN_ATOMICS 1
-#  else
-#   define GCC_BUILTIN_ATOMICS 0
-#  endif
-# else /* !__GNUC__ */
-#  define GCC_BUILTIN_ATOMICS  0
-# endif
-
 void  AcrCpuFence()
 {
     _PR_COMPILER_FENCE();
@@ -43,84 +33,54 @@ void  AcrMemoryFence()
 
 int AcrAtomic32Inc(volatile acr_atomic32_t *val)
 {
-#if GCC_BUILTIN_ATOMICS
-    return (int)__sync_add_and_fetch(val, 1);
-#else
     _PR_COMPILER_FENCE();
     return (int)(++(*val));
-#endif
 }
 
 int AcrAtomic32Dec(volatile acr_atomic32_t *val)
 {
-#if GCC_BUILTIN_ATOMICS
-    return (int)__sync_sub_and_fetch(val, 1);
-#else
     _PR_COMPILER_FENCE();
     return (int)(--(*val));
-#endif
 }
 
 int AcrAtomic32Cas(volatile acr_atomic32_t *val, int cmp, int set)
 {
-#if GCC_BUILTIN_ATOMICS
-    return (int)__sync_val_compare_and_swap(val, cmp, set);
-#else
     _PR_COMPILER_FENCE();
     acr_atomic32_t org = *val;
     if (org == (acr_atomic32_t)cmp)
         *val = (acr_atomic32_t)set;
     return (int)org;
-#endif
 }
 
 void *AcrAtomic32CasPtr(void * volatile *val, const void *cmp, void *set)
 {
-#if GCC_BUILTIN_ATOMICS
-    return (void *)__sync_val_compare_and_swap(val, cmp, set);
-#else
     _PR_COMPILER_FENCE();
     void *org = *((void **)val);
     if (org == cmp) {
         *val = set;
     }
     return org;
-#endif
 }
 
 int AcrAtomic32Set(volatile acr_atomic32_t *val, int num)
 {
-#if GCC_BUILTIN_ATOMICS
-    __sync_synchronize();
-    return (int)__sync_lock_test_and_set(val, num);
-#else
     _PR_COMPILER_FENCE();
     acr_atomic32_t org = *val;
     *val = num;
     return (int)org;
-#endif
 }
 
 void *AcrAtomic32SetPtr(void * volatile *val, void *set)
 {
-#if GCC_BUILTIN_ATOMICS
-    __sync_synchronize();
-    return (void *)__sync_lock_test_and_set(val, set);
-#else
     _PR_COMPILER_FENCE();
     void *org = *((void **)val);
     *val = set;
     return org;
-#endif
 }
 
 int AcrAtomic32Equ(volatile acr_atomic32_t *val, int num)
 {
-#if GCC_BUILTIN_ATOMICS
-    return __sync_bool_compare_and_swap(val, num, num);
-#else
     _PR_COMPILER_FENCE();
     return *val == (acr_atomic32_t)num;
-#endif
 }
 #endif /* USE_ATOMICS_WRAPPER */