From 957fa1379ceace8458cfca87da28f3cb8b7d7239 Mon Sep 17 00:00:00 2001 From: Edward O'Callaghan Date: Sat, 12 Sep 2009 16:29:10 +0000 Subject: [PATCH] GCC atomic built-ins are available patch to Blocks. - Credit to Bobby Powers. llvm-svn: 81615 --- compiler-rt/BlocksRuntime/runtime.c | 31 +++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/compiler-rt/BlocksRuntime/runtime.c b/compiler-rt/BlocksRuntime/runtime.c index 0a6df838ab7e..bd079bef8c96 100644 --- a/compiler-rt/BlocksRuntime/runtime.c +++ b/compiler-rt/BlocksRuntime/runtime.c @@ -28,24 +28,39 @@ #include #include -#if !TARGET_OS_WIN32 +#if TARGET_OS_MAC #include -#else +#elif TARGET_OS_WIN32 #define _CRT_SECURE_NO_WARNINGS 1 #include -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