]> Savannah Git Hosting - gnulib.git/commitdiff
asyncsafe-spin: Use GCC built-ins also on clang.
authorBruno Haible <bruno@clisp.org>
Tue, 11 Aug 2020 17:11:41 +0000 (19:11 +0200)
committerBruno Haible <bruno@clisp.org>
Tue, 11 Aug 2020 17:11:41 +0000 (19:11 +0200)
* lib/asyncsafe-spin.c (asyncsafe_spin_init, do_lock, do_unlock): Use
the newer GCC built-ins also on clang.

ChangeLog
lib/asyncsafe-spin.c

index 460e6f166336e687732f6316b07e86e3a54ce1de..84549c84bdd609e0f52bca9606f1705827afa562 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+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.
index 6ea5781b369faaebb03ef219c3c3699d65ab97cf..98d4fadb319cd7dbdcf6257297e3c187ff0d58eb 100644 (file)
@@ -67,9 +67,11 @@ asyncsafe_spin_destroy (asyncsafe_spinlock_t *lock)
    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>
  */
@@ -129,8 +131,10 @@ do_unlock (asyncsafe_spinlock_t *lock)
 
 #   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>  */
 
@@ -184,16 +188,17 @@ do_unlock (asyncsafe_spinlock_t *lock)
     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
@@ -216,7 +221,7 @@ static unsigned int
 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)"