curl_threads: always use native threads/mutex on Windows
No binary (build failed)
—
(log yok)
| @@ -27,7 +27,41 @@ | |
| #ifdef USE_THREADS | |
| - | #ifdef HAVE_THREADS_POSIX |
| + | #ifdef _WIN32 |
| + | |
| + | curl_thread_t Curl_thread_create( |
| + | CURL_THREAD_RETURN_T(CURL_STDCALL *func)(void *), void *arg) |
| + | { |
| + | curl_thread_t t = CreateThread(NULL, 0, func, arg, 0, NULL); |
| + | if(!t) { |
| + | DWORD gle = GetLastError(); |
| + | /* !checksrc! disable ERRNOVAR 1 */ |
| + | errno = (gle == ERROR_ACCESS_DENIED || |
| + | gle == ERROR_NOT_ENOUGH_MEMORY) ? |
| + | EACCES : EINVAL; |
| + | return curl_thread_t_null; |
| + | } |
| + | return t; |
| + | } |
| + | |
| + | void Curl_thread_destroy(curl_thread_t *hnd) |
| + | { |
| + | if(*hnd != curl_thread_t_null) { |
| + | CloseHandle(*hnd); |
| + | *hnd = curl_thread_t_null; |
| + | } |
| + | } |
| + | |
| + | int Curl_thread_join(curl_thread_t *hnd) |
| + | { |
| + | int ret = (WaitForSingleObjectEx(*hnd, INFINITE, FALSE) == WAIT_OBJECT_0); |
| + | |
| + | Curl_thread_destroy(hnd); |
| + | |
| + | return ret; |
| + | } |
| + | |
| + | #elif defined(HAVE_THREADS_POSIX) |
| struct Curl_actual_call { | |
| unsigned int (*func)(void *); | |
| @@ -95,48 +129,47 @@ int Curl_thread_join(curl_thread_t *hnd) | |
| return ret; | |
| } | |
| - | #elif defined(_WIN32) |
| + | #else |
| + | #error neither HAVE_THREADS_POSIX nor _WIN32 defined |
| + | #endif |
| + | #endif /* USE_THREADS */ |
| - | curl_thread_t Curl_thread_create( |
| - | CURL_THREAD_RETURN_T(CURL_STDCALL *func)(void *), void *arg) |
| + | #ifdef USE_MUTEX |
| + | |
| + | #ifdef _WIN32 |
| + | |
| + | void Curl_cond_signal(CONDITION_VARIABLE *c) |
| { | |
| - | curl_thread_t t = CreateThread(NULL, 0, func, arg, 0, NULL); |
| - | if(!t) { |
| - | DWORD gle = GetLastError(); |
| - | /* !checksrc! disable ERRNOVAR 1 */ |
| - | errno = (gle == ERROR_ACCESS_DENIED || |
| - | gle == ERROR_NOT_ENOUGH_MEMORY) ? |
| - | EACCES : EINVAL; |
| - | return curl_thread_t_null; |
| - | } |
| - | return t; |
| + | WakeConditionVariable(c); |
| } | |
| - | void Curl_thread_destroy(curl_thread_t *hnd) |
| + | void Curl_cond_wait(CONDITION_VARIABLE *c, CRITICAL_SECTION *m) |
| { | |
| - | if(*hnd != curl_thread_t_null) { |
| - | CloseHandle(*hnd); |
| - | *hnd = curl_thread_t_null; |
| - | } |
| + | SleepConditionVariableCS(c, m, INFINITE); |
| } | |
| - | int Curl_thread_join(curl_thread_t *hnd) |
| + | CURLcode Curl_cond_timedwait(CONDITION_VARIABLE *c, CRITICAL_SECTION *m, |
| + | uint32_t timeout_ms) |
| { | |
| - | int ret = (WaitForSingleObjectEx(*hnd, INFINITE, FALSE) == WAIT_OBJECT_0); |
| - | |
| - | Curl_thread_destroy(hnd); |
| - | |
| - | return ret; |
| + | if(!SleepConditionVariableCS(c, m, (DWORD)timeout_ms)) { |
| + | DWORD err = GetLastError(); |
| + | return (err == ERROR_TIMEOUT) ? |
| + | CURLE_OPERATION_TIMEDOUT : CURLE_UNRECOVERABLE_POLL; |
| + | } |
| + | return CURLE_OK; |
| } | |
| - | #else |
| - | #error neither HAVE_THREADS_POSIX nor _WIN32 defined |
| - | #endif |
| - | #endif /* USE_THREADS */ |
| + | curl_thread_id_t Curl_thread_get_current_id(void) |
| + | { |
| + | return GetCurrentThreadId(); |
| + | } |
| - | #ifdef USE_MUTEX |
| + | bool Curl_thread_is_current(curl_thread_id_t tid) |
| + | { |
| + | return tid == GetCurrentThreadId(); |
| + | } |
| - | #ifdef HAVE_THREADS_POSIX |
| + | #elif defined(HAVE_THREADS_POSIX) |
| void Curl_cond_signal(pthread_cond_t *c) | |
| { | |
| @@ -196,39 +229,6 @@ bool Curl_thread_is_current(curl_thread_id_t tid) | |
| return !!pthread_equal(tid, pthread_self()); | |
| } | |
| - | #elif defined(_WIN32) |
| - | |
| - | void Curl_cond_signal(CONDITION_VARIABLE *c) |
| - | { |
| - | WakeConditionVariable(c); |
| - | } |
| - | |
| - | void Curl_cond_wait(CONDITION_VARIABLE *c, CRITICAL_SECTION *m) |
| - | { |
| - | SleepConditionVariableCS(c, m, INFINITE); |
| - | } |
| - | |
| - | CURLcode Curl_cond_timedwait(CONDITION_VARIABLE *c, CRITICAL_SECTION *m, |
| - | uint32_t timeout_ms) |
| - | { |
| - | if(!SleepConditionVariableCS(c, m, (DWORD)timeout_ms)) { |
| - | DWORD err = GetLastError(); |
| - | return (err == ERROR_TIMEOUT) ? |
| - | CURLE_OPERATION_TIMEDOUT : CURLE_UNRECOVERABLE_POLL; |
| - | } |
| - | return CURLE_OK; |
| - | } |
| - | |
| - | curl_thread_id_t Curl_thread_get_current_id(void) |
| - | { |
| - | return GetCurrentThreadId(); |
| - | } |
| - | |
| - | bool Curl_thread_is_current(curl_thread_id_t tid) |
| - | { |
| - | return tid == GetCurrentThreadId(); |
| - | } |
| - | |
| #else | |
| #error neither HAVE_THREADS_POSIX nor _WIN32 defined | |
| #endif | |
| @@ -26,21 +26,7 @@ | |
| #include "curl_setup.h" | |
| #ifdef USE_MUTEX | |
| - | #ifdef HAVE_THREADS_POSIX |
| - | # define CURL_THREAD_RETURN_T unsigned int |
| - | # define CURL_STDCALL |
| - | # define curl_mutex_t pthread_mutex_t |
| - | # define curl_thread_t pthread_t * |
| - | # define curl_thread_id_t pthread_t |
| - | # define curl_thread_t_null (pthread_t *)0 |
| - | # define Curl_mutex_init(m) pthread_mutex_init(m, NULL) |
| - | # define Curl_mutex_acquire(m) pthread_mutex_lock(m) |
| - | # define Curl_mutex_release(m) pthread_mutex_unlock(m) |
| - | # define Curl_mutex_destroy(m) pthread_mutex_destroy(m) |
| - | # define curl_cond_t pthread_cond_t |
| - | # define Curl_cond_init(c) pthread_cond_init(c, NULL) |
| - | # define Curl_cond_destroy(c) pthread_cond_destroy(c) |
| - | #elif defined(_WIN32) |
| + | #ifdef _WIN32 |
| # define CURL_THREAD_RETURN_T DWORD | |
| # define CURL_STDCALL WINAPI | |
| # define curl_mutex_t CRITICAL_SECTION | |
| @@ -54,6 +40,20 @@ | |
| # define curl_cond_t CONDITION_VARIABLE | |
| # define Curl_cond_init(c) InitializeConditionVariable(c) | |
| # define Curl_cond_destroy(c) (void)(c) | |
| + | #elif defined(HAVE_THREADS_POSIX) |
| + | # define CURL_THREAD_RETURN_T unsigned int |
| + | # define CURL_STDCALL |
| + | # define curl_mutex_t pthread_mutex_t |
| + | # define curl_thread_t pthread_t * |
| + | # define curl_thread_id_t pthread_t |
| + | # define curl_thread_t_null (pthread_t *)0 |
| + | # define Curl_mutex_init(m) pthread_mutex_init(m, NULL) |
| + | # define Curl_mutex_acquire(m) pthread_mutex_lock(m) |
| + | # define Curl_mutex_release(m) pthread_mutex_unlock(m) |
| + | # define Curl_mutex_destroy(m) pthread_mutex_destroy(m) |
| + | # define curl_cond_t pthread_cond_t |
| + | # define Curl_cond_init(c) pthread_cond_init(c, NULL) |
| + | # define Curl_cond_destroy(c) pthread_cond_destroy(c) |
| #else | |
| #error neither HAVE_THREADS_POSIX nor _WIN32 defined | |
| #endif | |