diff options
author | Edward O'Callaghan <eocallaghan@auroraux.org> | 2009-09-12 16:29:10 +0000 |
---|---|---|
committer | Edward O'Callaghan <eocallaghan@auroraux.org> | 2009-09-12 16:29:10 +0000 |
commit | e8ce595140fa3f107db10a6b4d9184f7277e58c0 (patch) | |
tree | d0dd7dc32b12de7e91cc93b8e4b2353baf275d96 /BlocksRuntime | |
parent | 09870645031d5a05c7c3b9a66a53348a0d82ae52 (diff) |
GCC atomic built-ins are available patch to Blocks. - Credit to Bobby Powers.
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@81615 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'BlocksRuntime')
-rw-r--r-- | BlocksRuntime/runtime.c | 31 |
1 files changed, 23 insertions, 8 deletions
diff --git a/BlocksRuntime/runtime.c b/BlocksRuntime/runtime.c index 0a6df838a..bd079bef8 100644 --- a/BlocksRuntime/runtime.c +++ b/BlocksRuntime/runtime.c @@ -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 |