Index: src/atomic.h ================================================================== --- src/atomic.h +++ src/atomic.h @@ -16,15 +16,10 @@ #include #import "macros.h" -#if defined(OF_THREADS) && !defined(OF_X86_ASM) && !defined(OF_AMD64_ASM) && \ - !defined(OF_HAVE_GCC_ATOMIC_OPS) && !defined(OF_HAVE_OSATOMIC) -# error No atomic operations available! -#endif - #ifdef OF_HAVE_OSATOMIC # include #endif static OF_INLINE int @@ -64,10 +59,12 @@ else if (sizeof(int) == 8) return OSAtomicAdd64Barrier(i, p); # endif else abort(); +#else +# error No atomic operations available! #endif } static OF_INLINE int32_t of_atomic_add_32(volatile int32_t *p, int32_t i) @@ -86,10 +83,12 @@ return i; #elif defined(OF_HAVE_GCC_ATOMIC_OPS) return __sync_add_and_fetch(p, i); #elif defined(OF_HAVE_OSATOMIC) return OSAtomicAdd32Barrier(i, p); +#else +# error No atomic operations available! #endif } static OF_INLINE void* of_atomic_add_ptr(void* volatile *p, intptr_t i) @@ -125,10 +124,12 @@ else if (sizeof(void*) == 8) return (void*)OSAtomicAdd64Barrier(i, (int64_t*)p); # endif else abort(); +#else +# error No atomic operations available! #endif } static OF_INLINE int of_atomic_sub_int(volatile int *p, int i) @@ -169,10 +170,12 @@ else if (sizeof(int) == 8) return OSAtomicAdd64Barrier(-i, p); # endif else abort(); +#else +# error No atomic operations available! #endif } static OF_INLINE int32_t of_atomic_sub_32(volatile int32_t *p, int32_t i) @@ -192,10 +195,12 @@ return i; #elif defined(OF_HAVE_GCC_ATOMIC_OPS) return __sync_sub_and_fetch(p, i); #elif defined(OF_HAVE_OSATOMIC) return OSAtomicAdd32Barrier(-i, p); +#else +# error No atomic operations available! #endif } static OF_INLINE void* of_atomic_sub_ptr(void* volatile *p, intptr_t i) @@ -233,20 +238,22 @@ else if (sizeof(void*) == 8) return (void*)OSAtomicAdd64Barrier(-i, (int64_t*)p); # endif else abort(); +#else +# error No atomic operations available! #endif } static OF_INLINE int of_atomic_inc_int(volatile int *p) { #if !defined(OF_THREADS) return ++*p; #elif defined(OF_X86_ASM) || defined(OF_AMD64_ASM) - uint32_t i; + int i; if (sizeof(int) == 4) __asm__ ( "xorl %0, %0\n\t" "incl %0\n\t" @@ -281,12 +288,15 @@ else if (sizeof(int) == 8) return OSAtomicDecrement64Barrier(p); # endif else abort(); +#else +# error No atomic operations available! #endif } + static OF_INLINE int32_t of_atomic_inc_32(volatile int32_t *p) { #if !defined(OF_THREADS) return ++*p; @@ -306,20 +316,22 @@ return i; #elif defined(OF_HAVE_GCC_ATOMIC_OPS) return __sync_add_and_fetch(p, 1); #elif defined(OF_HAVE_OSATOMIC) return OSAtomicIncrement32Barrier(p); +#else +# error No atomic operations available! #endif } static OF_INLINE int of_atomic_dec_int(volatile int *p) { #if !defined(OF_THREADS) return --*p; #elif defined(OF_X86_ASM) || defined(OF_AMD64_ASM) - uint32_t i; + int i; if (sizeof(int) == 4) __asm__ ( "xorl %0, %0\n\t" "decl %0\n\t" @@ -354,10 +366,12 @@ else if (sizeof(int) == 8) return OSAtomicDecrement64Barrier(p); # endif else abort(); +#else +# error No atomic operations available! #endif } static OF_INLINE int32_t of_atomic_dec_32(volatile int32_t *p) @@ -380,10 +394,12 @@ return i; #elif defined(OF_HAVE_GCC_ATOMIC_OPS) return __sync_sub_and_fetch(p, 1); #elif defined(OF_HAVE_OSATOMIC) return OSAtomicDecrement32Barrier(p); +#else +# error No atomic operations available! #endif } static OF_INLINE unsigned int of_atomic_or_int(volatile unsigned int *p, unsigned int i) @@ -432,10 +448,12 @@ else if (sizeof(int) == 8) return OSAtomicOr64Barrier(i, p); # endif else abort(); +#else +# error No atomic operations available! #endif } static OF_INLINE uint32_t of_atomic_or_32(volatile uint32_t *p, uint32_t i) @@ -459,10 +477,12 @@ return i; #elif defined(OF_HAVE_GCC_ATOMIC_OPS) return __sync_or_and_fetch(p, i); #elif defined(OF_HAVE_OSATOMIC) return OSAtomicOr32Barrier(i, p); +#else +# error No atomic operations available! #endif } static OF_INLINE unsigned int of_atomic_and_int(volatile unsigned int *p, unsigned int i) @@ -511,10 +531,12 @@ else if (sizeof(int) == 8) return OSAtomicAnd64Barrier(i, p); # endif else abort(); +#else +# error No atomic operations available! #endif } static OF_INLINE uint32_t of_atomic_and_32(volatile uint32_t *p, uint32_t i) @@ -538,10 +560,12 @@ return i; #elif defined(OF_HAVE_GCC_ATOMIC_OPS) return __sync_and_and_fetch(p, i); #elif defined(OF_HAVE_OSATOMIC) return OSAtomicAnd32Barrier(i, p); +#else +# error No atomic operations available! #endif } static OF_INLINE unsigned int of_atomic_xor_int(volatile unsigned int *p, unsigned int i) @@ -590,10 +614,12 @@ else (sizeof(int) == 8) return OSAtomicXor64Barrier(i, p); # endif else abort(); +#else +# error No atomic operations available! #endif } static OF_INLINE uint32_t of_atomic_xor_32(volatile uint32_t *p, uint32_t i) @@ -617,10 +643,12 @@ return i; #elif defined(OF_HAVE_GCC_ATOMIC_OPS) return __sync_xor_and_fetch(p, i); #elif defined(OF_HAVE_OSATOMIC) return OSAtomicXor32Barrier(i, p); +#else +# error No atomic operations available! #endif } static OF_INLINE BOOL of_atomic_cmpswap_int(volatile int *p, int o, int n) @@ -648,10 +676,12 @@ return r; #elif defined(OF_HAVE_GCC_ATOMIC_OPS) return __sync_bool_compare_and_swap(p, o, n); #elif defined(OF_HAVE_OSATOMIC) return OSAtomicCompareAndSwapIntBarrier(o, n, p); +#else +# error No atomic operations available! #endif } static OF_INLINE BOOL of_atomic_cmpswap_32(volatile int32_t *p, int32_t o, int32_t n) @@ -679,10 +709,12 @@ return r; #elif defined(OF_HAVE_GCC_ATOMIC_OPS) return __sync_bool_compare_and_swap(p, o, n); #elif defined(OF_HAVE_OSATOMIC) return OSAtomicCompareAndSwap32Barrier(o, n, p); +#else +# error No atomic operations available! #endif } static OF_INLINE BOOL of_atomic_cmpswap_ptr(void* volatile *p, void *o, void *n) @@ -710,7 +742,9 @@ return r; #elif defined(OF_HAVE_GCC_ATOMIC_OPS) return __sync_bool_compare_and_swap(p, o, n); #elif defined(OF_HAVE_OSATOMIC) return OSAtomicCompareAndSwapPtrBarrier(o, n, p); +#else +# error No atomic operations available! #endif }