pthread-spin: Use GCC built-ins also on clang.
authorBruno Haible <bruno@clisp.org>
Sun, 16 Aug 2020 16:42:02 +0000 (18:42 +0200)
committerBruno Haible <bruno@clisp.org>
Sun, 16 Aug 2020 16:42:02 +0000 (18:42 +0200)
* lib/pthread-spin.c (pthread_spin_init, pthread_spin_lock,
pthread_spin_trylock, pthread_spin_unlock): Use the newer GCC built-ins
also on clang.

ChangeLog
lib/pthread-spin.c

index 0f7ca8e7d73cfc863434c88af2fdd4f0eba8b17b..b97fcf77cd50266a7ef72f27721858298463b70c 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2020-08-16  Bruno Haible  <bruno@clisp.org>
+
+       pthread-spin: Use GCC built-ins also on clang.
+       * lib/pthread-spin.c (pthread_spin_init, pthread_spin_lock,
+       pthread_spin_trylock, pthread_spin_unlock): Use the newer GCC built-ins
+       also on clang.
+
 2020-08-16  Bruno Haible  <bruno@clisp.org>
 
        asyncsafe-spin tests: Update.
index c13105046d2d6215d28920bf7c530a49d3ab88b2..c343f9d4b1e556ddc594280f3913d6312c190cb6 100644 (file)
@@ -68,9 +68,11 @@ pthread_spin_destroy (pthread_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)
-/* Use GCC built-ins (available in GCC >= 4.7) that operate on the first 32-bit
-   word 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>  */
 
@@ -162,8 +164,10 @@ pthread_spin_destroy (pthread_spinlock_t *lock)
   return 0;
 }
 
-# elif __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 1)
-/* 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>  */