20 #ifndef OF_HAVE_ATOMIC_OPS
21 # error No atomic operations available!
24 #if !defined(OF_HAVE_THREADS)
26 OFAtomicIntAdd(
volatile int *_Nonnull p,
int i)
31 static OF_INLINE int32_t
32 OFAtomicInt32Add(
volatile int32_t *_Nonnull p, int32_t i)
37 static OF_INLINE
void *_Nullable
38 OFAtomicPointerAdd(
void *
volatile _Nullable *_Nonnull p, intptr_t i)
40 return (*(
char *
volatile *)p += i);
44 OFAtomicIntSubtract(
volatile int *_Nonnull p,
int i)
49 static OF_INLINE int32_t
50 OFAtomicInt32Subtract(
volatile int32_t *_Nonnull p, int32_t i)
55 static OF_INLINE
void *_Nullable
56 OFAtomicPointerSubtract(
void *
volatile _Nullable *_Nonnull p, intptr_t i)
58 return (*(
char *
volatile *)p -= i);
62 OFAtomicIntIncrease(
volatile int *_Nonnull p)
67 static OF_INLINE int32_t
68 OFAtomicInt32Increase(
volatile int32_t *_Nonnull p)
74 OFAtomicIntDecrease(
volatile int *_Nonnull p)
79 static OF_INLINE int32_t
80 OFAtomicInt32Decrease(
volatile int32_t *_Nonnull p)
85 static OF_INLINE
unsigned int
86 OFAtomicIntOr(
volatile unsigned int *_Nonnull p,
unsigned int i)
91 static OF_INLINE uint32_t
92 OFAtomicInt32Or(
volatile uint32_t *_Nonnull p, uint32_t i)
97 static OF_INLINE
unsigned int
98 OFAtomicIntAnd(
volatile unsigned int *_Nonnull p,
unsigned int i)
103 static OF_INLINE uint32_t
104 OFAtomicInt32And(
volatile uint32_t *_Nonnull p, uint32_t i)
109 static OF_INLINE
unsigned int
110 OFAtomicIntXor(
volatile unsigned int *_Nonnull p,
unsigned int i)
115 static OF_INLINE uint32_t
116 OFAtomicInt32Xor(
volatile uint32_t *_Nonnull p, uint32_t i)
121 static OF_INLINE
bool
122 OFAtomicIntCompareAndSwap(
volatile int *_Nonnull p,
int o,
int n)
132 static OF_INLINE
bool
133 OFAtomicInt32CompareAndSwap(
volatile int32_t *_Nonnull p, int32_t o, int32_t n)
143 static OF_INLINE
bool
144 OFAtomicPointerCompareAndSwap(
void *
volatile _Nullable *_Nonnull p,
145 void *_Nullable o,
void *_Nullable n)
155 static OF_INLINE
void
156 OFMemoryBarrier(
void)
161 static OF_INLINE
void
162 OFAcquireMemoryBarrier(
void)
167 static OF_INLINE
void
168 OFReleaseMemoryBarrier(
void)
172 #elif (defined(OF_AMD64) || defined(OF_X86)) && defined(__GNUC__)
173 # import "platform/x86/OFAtomic.h"
174 #elif defined(OF_POWERPC) && defined(__GNUC__) && !defined(__APPLE_CC__) && \
176 # import "platform/PowerPC/OFAtomic.h"
177 #elif defined(OF_HAVE_ATOMIC_BUILTINS)
178 # import "platform/GCC4.7/OFAtomic.h"
179 #elif defined(OF_HAVE_SYNC_BUILTINS)
180 # import "platform/GCC4/OFAtomic.h"
181 #elif defined(OF_HAVE_OSATOMIC)
182 # import "platform/macOS/OFAtomic.h"
184 # error No atomic operations available!