]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
easy_lock: add a pthread_mutex_t fallback
authorLoïc Yhuel <loic.yhuel@softathome.com>
Wed, 11 Oct 2023 11:07:48 +0000 (13:07 +0200)
committerJay Satiro <raysatiro@yahoo.com>
Fri, 13 Oct 2023 03:40:08 +0000 (23:40 -0400)
This allows to keep the init threadsafe with gcc < 4.9.0 (no C11
atomics).

Closes https://github.com/curl/curl/pull/12090

lib/easy_lock.h

index d3fffd0d2a2bfb22f303131cdb4f460067e0379d..4f6764d427dec043777681f2b5cda656c2923079 100644 (file)
@@ -93,6 +93,15 @@ static inline void curl_simple_lock_unlock(curl_simple_lock *lock)
   atomic_store_explicit(lock, false, memory_order_release);
 }
 
+#elif defined(USE_THREADS_POSIX) && defined(HAVE_PTHREAD_H)
+
+#include <pthread.h>
+
+#define curl_simple_lock pthread_mutex_t
+#define CURL_SIMPLE_LOCK_INIT PTHREAD_MUTEX_INITIALIZER
+#define curl_simple_lock_lock(m) pthread_mutex_lock(m)
+#define curl_simple_lock_unlock(m) pthread_mutex_unlock(m)
+
 #else
 
 #undef  GLOBAL_INIT_IS_THREADSAFE