commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mt...@apache.org
Subject svn commit: r1139528 - /commons/sandbox/runtime/trunk/src/main/native/os/unix/atomic.c
Date Sat, 25 Jun 2011 11:49:47 GMT
Author: mturk
Date: Sat Jun 25 11:49:46 2011
New Revision: 1139528

URL: http://svn.apache.org/viewvc?rev=1139528&view=rev
Log:
Make common code more generic

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

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=1139528&r1=1139527&r2=1139528&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:49:46 2011
@@ -22,6 +22,15 @@
 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();
@@ -34,7 +43,7 @@ void  AcrMemoryFence()
 
 int AcrAtomic32Inc(volatile acr_atomic32_t *val)
 {
-#if USE_BUILTIN_ATOMICS
+#if GCC_BUILTIN_ATOMICS
     return (int)__sync_add_and_fetch(val, 1);
 #else
     _PR_COMPILER_FENCE();
@@ -44,7 +53,7 @@ int AcrAtomic32Inc(volatile acr_atomic32
 
 int AcrAtomic32Dec(volatile acr_atomic32_t *val)
 {
-#if USE_BUILTIN_ATOMICS
+#if GCC_BUILTIN_ATOMICS
     return (int)__sync_sub_and_fetch(val, 1);
 #else
     _PR_COMPILER_FENCE();
@@ -54,7 +63,7 @@ int AcrAtomic32Dec(volatile acr_atomic32
 
 int AcrAtomic32Cas(volatile acr_atomic32_t *val, int cmp, int set)
 {
-#if USE_BUILTIN_ATOMICS
+#if GCC_BUILTIN_ATOMICS
     return (int)__sync_val_compare_and_swap(val, cmp, set);
 #else
     _PR_COMPILER_FENCE();
@@ -67,7 +76,7 @@ int AcrAtomic32Cas(volatile acr_atomic32
 
 void *AcrAtomic32CasPtr(void * volatile *val, const void *cmp, void *set)
 {
-#if USE_BUILTIN_ATOMICS
+#if GCC_BUILTIN_ATOMICS
     return (void *)__sync_val_compare_and_swap(val, cmp, set);
 #else
     _PR_COMPILER_FENCE();
@@ -81,7 +90,7 @@ void *AcrAtomic32CasPtr(void * volatile 
 
 int AcrAtomic32Set(volatile acr_atomic32_t *val, int num)
 {
-#if USE_BUILTIN_ATOMICS
+#if GCC_BUILTIN_ATOMICS
     __sync_synchronize();
     return (int)__sync_lock_test_and_set(val, num);
 #else
@@ -94,7 +103,7 @@ int AcrAtomic32Set(volatile acr_atomic32
 
 void *AcrAtomic32SetPtr(void * volatile *val, void *set)
 {
-#if USE_BUILTIN_ATOMICS
+#if GCC_BUILTIN_ATOMICS
     __sync_synchronize();
     return (void *)__sync_lock_test_and_set(val, set);
 #else
@@ -107,14 +116,11 @@ void *AcrAtomic32SetPtr(void * volatile 
 
 int AcrAtomic32Equ(volatile acr_atomic32_t *val, int num)
 {
-#if USE_BUILTIN_ATOMICS
+#if GCC_BUILTIN_ATOMICS
     return __sync_bool_compare_and_swap(val, num, num);
 #else
     _PR_COMPILER_FENCE();
     return *val == (acr_atomic32_t)num;
 #endif
 }
-# else /* !__GNUC__ */
-#  error "Atomics are not implemented for this platform!"
-# endif
 #endif /* USE_ATOMICS_WRAPPER */



Mime
View raw message