atomics: Define HAVE_GCC_ATOMIC_OPERATIONS when building with clang
authorTobias Brunner <tobias@strongswan.org>
Tue, 5 Jun 2018 13:58:08 +0000 (15:58 +0200)
committerTobias Brunner <tobias@strongswan.org>
Tue, 3 Jul 2018 09:31:31 +0000 (11:31 +0200)
We should probably check for stdatomic.h and use the c11 functions if
available.

src/libstrongswan/utils/utils/atomics.h

index a973b1a..4b530eb 100644 (file)
  */
 typedef u_int refcount_t;
 
+/* use __atomic* built-ins with clang, if available (note that clang also
+ * defines __GNUC__, however only claims to be GCC 4.2) */
+#if defined(__clang__)
+# if __has_builtin(__atomic_add_fetch)
+#  define HAVE_GCC_ATOMIC_OPERATIONS
+# endif
 /* use __atomic* built-ins with GCC 4.7 and newer */
-#ifdef __GNUC__
+#elif defined(__GNUC__)
 # if (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ > 6))
 #  define HAVE_GCC_ATOMIC_OPERATIONS
 # endif