From 33fd57b8fff8c0d873da2316a2a7f911caac2bae Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Tue, 28 Jun 2022 10:21:07 +0200 Subject: [PATCH] easy_lock: fix the #ifdef conditional for ia32_pause 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 | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/easy_lock.h b/lib/easy_lock.h index 9c11bc50c5..a4db9fe47e 100644 --- a/lib/easy_lock.h +++ b/lib/easy_lock.h @@ -43,6 +43,18 @@ #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");