base: use <stdatomic.h> for atomics, where present
C11 introduces a new set of atomic APIs in <stdatomic.h>. If available, use those in preference to compiler- or platform-specific intrinsics.
This commit is contained in:
@@ -412,6 +412,7 @@ AC_CHECK_HEADERS([\
|
|||||||
signal.h \
|
signal.h \
|
||||||
strings.h \
|
strings.h \
|
||||||
stropts.h \
|
stropts.h \
|
||||||
|
stdatomic.h \
|
||||||
sys/bitypes.h \
|
sys/bitypes.h \
|
||||||
sys/category.h \
|
sys/category.h \
|
||||||
sys/file.h \
|
sys/file.h \
|
||||||
|
@@ -42,7 +42,20 @@
|
|||||||
* Atomic operations
|
* Atomic operations
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#if defined(__GNUC__) && defined(HAVE___SYNC_ADD_AND_FETCH)
|
#if defined(HAVE_STDATOMIC_H)
|
||||||
|
|
||||||
|
#include <stdatomic.h>
|
||||||
|
|
||||||
|
#define heim_base_atomic_inc(x) (atomic_fetch_add((x), 1) + 1)
|
||||||
|
#define heim_base_atomic_dec(x) (atomic_fetch_sub((x), 1) - 1)
|
||||||
|
#define heim_base_atomic_type atomic_uint
|
||||||
|
#define heim_base_atomic_max UINT_MAX
|
||||||
|
|
||||||
|
#define heim_base_exchange_pointer(t,v) atomic_exchange((t), (v))
|
||||||
|
#define heim_base_exchange_32(t,v) atomic_exchange((t), (v))
|
||||||
|
#define heim_base_exchange_64(t,v) atomic_exchange((t), (v))
|
||||||
|
|
||||||
|
#elif defined(__GNUC__) && defined(HAVE___SYNC_ADD_AND_FETCH)
|
||||||
|
|
||||||
#define heim_base_atomic_inc(x) __sync_add_and_fetch((x), 1)
|
#define heim_base_atomic_inc(x) __sync_add_and_fetch((x), 1)
|
||||||
#define heim_base_atomic_dec(x) __sync_sub_and_fetch((x), 1)
|
#define heim_base_atomic_dec(x) __sync_sub_and_fetch((x), 1)
|
||||||
|
Reference in New Issue
Block a user