From 123dcfaec5469d56e4780eb8b5261645e36fcd2a Mon Sep 17 00:00:00 2001 From: Rob Donnelly Date: Thu, 15 Aug 2019 09:50:58 -0700 Subject: [PATCH] Fix compile on older versions of GCC and CLANG (#427) Older versions of GCC (<4.9) and LLVM (<3.6) do not have __atomic_load_n which is part of the C11 standard. Fix by falling back to __sync_fetch_and_add with a value of 0 when __atomic_load_n is not available. Fixes #423 Co-authored-by: Max Brunsfeld --- lib/src/atomic.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/src/atomic.h b/lib/src/atomic.h index 1df4ce08..301ee367 100644 --- a/lib/src/atomic.h +++ b/lib/src/atomic.h @@ -22,7 +22,11 @@ static inline uint32_t atomic_dec(volatile uint32_t *p) { #else static inline size_t atomic_load(const volatile size_t *p) { +#ifdef __ATOMIC_RELAXED return __atomic_load_n(p, __ATOMIC_RELAXED); +#else + return __sync_fetch_and_add((volatile size_t *)p, 0); +#endif } static inline uint32_t atomic_inc(volatile uint32_t *p) {