+2020-08-11 Bruno Haible <bruno@clisp.org>
+
+ asyncsafe-spin: Use GCC built-ins also on clang.
+ * lib/asyncsafe-spin.c (asyncsafe_spin_init, do_lock, do_unlock): Use
+ the newer GCC built-ins also on clang.
+
2020-08-11 Bruno Haible <bruno@clisp.org>
Use expression statements also on clang.
We don't use the C11 <stdatomic.h> (available in GCC >= 4.9) because it would
require to link with -latomic. */
-# if (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 7)) && !defined __ibmxl__
-/* Use GCC built-ins (available in GCC >= 4.7) that operate on the first byte of
- the lock.
+# if (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 7) \
+ || __clang_major > 3 || (__clang_major__ == 3 && __clang_minor__ >= 1)) \
+ && !defined __ibmxl__
+/* Use GCC built-ins (available in GCC >= 4.7 and clang >= 3.1) that operate on
+ the first byte of the lock.
Documentation:
<https://gcc.gnu.org/onlinedocs/gcc-4.7.0/gcc/_005f_005fatomic-Builtins.html>
*/
# endif
-# elif (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 1)) && !defined __ibmxl__
-/* Use GCC built-ins (available in GCC >= 4.1).
+# elif (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 1) \
+ || __clang_major__ >= 3) \
+ && !defined __ibmxl__
+/* Use GCC built-ins (available in GCC >= 4.1 and clang >= 3.0).
Documentation:
<https://gcc.gnu.org/onlinedocs/gcc-4.1.2/gcc/Atomic-Builtins.html> */
abort ();
}
-# elif (defined __GNUC__ || defined __SUNPRO_C) && (defined __sparc || defined __i386 || defined __x86_64__)
-/* For older versions of GCC, use inline assembly.
- GCC and the Oracle Studio C 12 compiler understand GCC's extended asm syntax,
- but the plain Oracle Studio C 11 compiler understands only simple asm. */
+# elif (defined __GNUC__ || defined __clang__ || defined __SUNPRO_C) && (defined __sparc || defined __i386 || defined __x86_64__)
+/* For older versions of GCC or clang, use inline assembly.
+ GCC, clang, and the Oracle Studio C 12 compiler understand GCC's extended
+ asm syntax, but the plain Oracle Studio C 11 compiler understands only
+ simple asm. */
/* An implementation that verifies the unlocks. */
static void
memory_barrier (void)
{
-# if defined __GNUC__ || __SUNPRO_C >= 0x590
+# if defined __GNUC__ || defined __clang__ || __SUNPRO_C >= 0x590
# if defined __i386 || defined __x86_64__
asm volatile ("mfence");
# endif
atomic_compare_and_swap (volatile unsigned int *vp, unsigned int cmp,
unsigned int newval)
{
-# if defined __GNUC__ || __SUNPRO_C >= 0x590
+# if defined __GNUC__ || defined __clang__ || __SUNPRO_C >= 0x590
unsigned int oldval;
# if defined __i386 || defined __x86_64__
asm volatile (" lock\n cmpxchgl %3,(%1)"