]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
easy_lock: fix the #ifdef conditional for ia32_pause
authorDaniel Stenberg <daniel@haxx.se>
Tue, 28 Jun 2022 08:21:07 +0000 (10:21 +0200)
committerDaniel Stenberg <daniel@haxx.se>
Tue, 28 Jun 2022 14:56:50 +0000 (16:56 +0200)
To work better with new and old clang compilers.

Reported-by: Ryan Schmidt
Assisted-by: Joshua Root
Fixes #9058
Closes #9062

lib/easy_lock.h

index 9c11bc50c5f20f9a13a6d7d62fd45f7877582dba..a4db9fe47e96e9250f4edaf314b65771f153f300 100644 (file)
 #define curl_simple_lock atomic_int
 #define CURL_SIMPLE_LOCK_INIT 0
 
+/* a clang-thing */
+#ifndef __has_builtin
+#define __has_builtin(x) 0
+#endif
+
+/* if GCC on i386/x86_64 or if the built-in is present */
+#if ( (defined(__GNUC__) && !defined(__clang__)) &&     \
+      (defined(__i386__) || defined(__x86_64__))) ||    \
+  __has_builtin(__builtin_ia32_pause)
+#define HAVE_BUILTIN_IA32_PAUSE
+#endif
+
 static inline void curl_simple_lock_lock(curl_simple_lock *lock)
 {
   for(;;) {
@@ -51,7 +63,7 @@ static inline void curl_simple_lock_lock(curl_simple_lock *lock)
     /* Reduce cache coherency traffic */
     while(atomic_load_explicit(lock, memory_order_relaxed)) {
       /* Reduce load (not mandatory) */
-#if defined(__i386__) || defined(__x86_64__)
+#ifdef HAVE_BUILTIN_IA32_PAUSE
       __builtin_ia32_pause();
 #elif defined(__aarch64__)
       __asm__ volatile("yield" ::: "memory");