> clang also has the atomic built-ins and the asm support that GCC has.
> 
> 
> 2020-08-11  Bruno Haible  <br...@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.

The tests need an update for this change. And the same GCC built-ins can
also be used in the module 'pthread-spin'.


2020-08-16  Bruno Haible  <br...@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  <br...@clisp.org>

        asyncsafe-spin tests: Update.
        * tests/test-asyncsafe-spin2.c: Update to match the change in
        lib/asyncsafe-spin.c from 2020-08-11.

>From dcc8b493adecff06096bb3516aac26d29012cf1a Mon Sep 17 00:00:00 2001
From: Bruno Haible <br...@clisp.org>
Date: Sun, 16 Aug 2020 18:41:57 +0200
Subject: [PATCH 1/2] asyncsafe-spin tests: Update.

* tests/test-asyncsafe-spin2.c: Update to match the change in
lib/asyncsafe-spin.c from 2020-08-11.
---
 ChangeLog                    | 6 ++++++
 tests/test-asyncsafe-spin2.c | 3 ++-
 2 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/ChangeLog b/ChangeLog
index b750f34..0f7ca8e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,11 @@
 2020-08-16  Bruno Haible  <br...@clisp.org>
 
+	asyncsafe-spin tests: Update.
+	* tests/test-asyncsafe-spin2.c: Update to match the change in
+	lib/asyncsafe-spin.c from 2020-08-11.
+
+2020-08-16  Bruno Haible  <br...@clisp.org>
+
 	setenv: Use tree code also with clang.
 	* lib/setenv.c (USE_TSEARCH): Treat clang like GCC.
 
diff --git a/tests/test-asyncsafe-spin2.c b/tests/test-asyncsafe-spin2.c
index cb0364f..38d9324 100644
--- a/tests/test-asyncsafe-spin2.c
+++ b/tests/test-asyncsafe-spin2.c
@@ -36,7 +36,8 @@
 #define THREAD_COUNT 10
 
 /* Number of operations performed in each thread.  */
-#if !(defined _WIN32 && ! defined __CYGWIN__) && HAVE_PTHREAD_H && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 1)) && !defined __ibmxl__
+#if !(defined _WIN32 && ! defined __CYGWIN__) && HAVE_PTHREAD_H && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 1) || __clang_major__ >= 3) && !defined __ibmxl__
+
 /* The GCC built-ins are known to work fine.  */
 # define REPEAT_COUNT 5000
 #else
-- 
2.7.4

>From bed51ff8cc7bb755b32fa83c589436d8221380c6 Mon Sep 17 00:00:00 2001
From: Bruno Haible <br...@clisp.org>
Date: Sun, 16 Aug 2020 18:42:02 +0200
Subject: [PATCH 2/2] 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.
---
 ChangeLog          |  7 +++++++
 lib/pthread-spin.c | 14 +++++++++-----
 2 files changed, 16 insertions(+), 5 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 0f7ca8e..b97fcf7 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,12 @@
 2020-08-16  Bruno Haible  <br...@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  <br...@clisp.org>
+
 	asyncsafe-spin tests: Update.
 	* tests/test-asyncsafe-spin2.c: Update to match the change in
 	lib/asyncsafe-spin.c from 2020-08-11.
diff --git a/lib/pthread-spin.c b/lib/pthread-spin.c
index c131050..c343f9d 100644
--- a/lib/pthread-spin.c
+++ b/lib/pthread-spin.c
@@ -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>  */
 
-- 
2.7.4

Reply via email to