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
This commit is contained in:
Daniel Stenberg 2022-06-28 10:21:07 +02:00
parent 50efb0822a
commit 33fd57b8ff
No known key found for this signature in database
GPG Key ID: 5CC908FDB71E12C2

View File

@ -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");