[llvm-commits] [compiler-rt] r81615 - /compiler-rt/trunk/BlocksRuntime/runtime.c

Edward O'Callaghan eocallaghan at auroraux.org
Sat Sep 12 09:29:10 PDT 2009


Author: evocallaghan
Date: Sat Sep 12 11:29:10 2009
New Revision: 81615

URL: http://llvm.org/viewvc/llvm-project?rev=81615&view=rev
Log:
GCC atomic built-ins are available patch to Blocks. - Credit to Bobby Powers.

Modified:
    compiler-rt/trunk/BlocksRuntime/runtime.c

Modified: compiler-rt/trunk/BlocksRuntime/runtime.c
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/BlocksRuntime/runtime.c?rev=81615&r1=81614&r2=81615&view=diff

==============================================================================
--- compiler-rt/trunk/BlocksRuntime/runtime.c (original)
+++ compiler-rt/trunk/BlocksRuntime/runtime.c Sat Sep 12 11:29:10 2009
@@ -28,24 +28,39 @@
 #include <string.h>
 #include <stdint.h>
 
-#if !TARGET_OS_WIN32
+#if TARGET_OS_MAC
 #include <libkern/OSAtomic.h>
-#else
+#elif TARGET_OS_WIN32
 #define _CRT_SECURE_NO_WARNINGS 1
 #include <windows.h>
-static __inline bool OSAtomicCompareAndSwapLong(long oldl, long newl, long volatile *dst) 
-{ 
-    // fixme barrier is overkill -- see objc-os.h
+static __inline bool OSAtomicCompareAndSwapLong(long oldl, long newl, long volatile *dst)
+{
+    /* fixme barrier is overkill -- see objc-os.h */
     long original = InterlockedCompareExchange(dst, newl, oldl);
     return (original == oldl);
 }
 
-static __inline bool OSAtomicCompareAndSwapInt(int oldi, int newi, int volatile *dst) 
-{ 
-    // fixme barrier is overkill -- see objc-os.h
+static __inline bool OSAtomicCompareAndSwapInt(int oldi, int newi, int volatile *dst)
+{
+    /* fixme barrier is overkill -- see objc-os.h */
     int original = InterlockedCompareExchange(dst, newi, oldi);
     return (original == oldi);
 }
+/* check to see if the GCC atomic built-ins are available.  if we're on
+ * a 64-bit system, make sure we have an 8-byte atomic function
+ * available.
+ */
+#elif __GCC_HAVE_SYNC_COMPARE_AND_SWAP_4 && \
+      ((__SIZEOF_LONG__ != 8) || __GCC_HAVE_SYNC_COMPARE_AND_SWAP_8)
+static __inline bool OSAtomicCompareAndSwapLong(long oldl, long newl, long volatile *dst)
+{
+  return __sync_bool_compare_and_swap(dst, oldl, newl);
+}
+
+static __inline bool OSAtomicCompareAndSwapInt(int oldi, int newi, int volatile *dst)
+{
+  return __sync_bool_compare_and_swap(dst, oldi, newi);
+}
 #endif
 
 





More information about the llvm-commits mailing list