SQLite Forum

[PATCH] Use C11's stdatomic.h when available
Login

[PATCH] Use C11's stdatomic.h when available

(1) By anonymous on 2021-05-02 13:59:53 [source]

Index: src/sqliteInt.h
==================================================================
--- src/sqliteInt.h
+++ src/sqliteInt.h
@@ -212,11 +212,15 @@
 ** places.  The following macros try to make this explicit.
 */
 #ifndef __has_extension
 # define __has_extension(x) 0     /* compatibility with non-clang compilers */
 #endif
-#if GCC_VERSION>=4007000 || \
+#if __STDC_VERSION__ >= 201112L && !defined(__STDC_NO_ATOMICS__)
+# include <stdatomic.h>
+# define AtomicLoad(PTR)       atomic_load_explicit((PTR),memory_order_relaxed)
+# define AtomicStore(PTR,VAL)  atomic_store_explicit((PTR),(VAL),memory_order_relaxed)
+#elif GCC_VERSION>=4007000 || \
     (__has_extension(c_atomic) && __has_extension(c_atomic_store_n))
 # define AtomicLoad(PTR)       __atomic_load_n((PTR),__ATOMIC_RELAXED)
 # define AtomicStore(PTR,VAL)  __atomic_store_n((PTR),(VAL),__ATOMIC_RELAXED)
 #else
 # define AtomicLoad(PTR)       (*(PTR))