From 01385ef1e9876209f2226d3aa78251032ed29b6c Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Wed, 3 Sep 2025 23:10:34 +0200 Subject: [PATCH] try moving win32 to CreateThread() API 2 --- lib/curl_setup.h | 3 --- lib/curl_threads.c | 11 +++-------- lib/curl_threads.h | 2 +- tests/libtest/lib3026.c | 9 ++++----- tests/server/sockfilt.c | 9 +++------ tests/server/util.c | 11 ++++------- 6 files changed, 15 insertions(+), 30 deletions(-) diff --git a/lib/curl_setup.h b/lib/curl_setup.h index b97afd1986..517769c3b4 100644 --- a/lib/curl_setup.h +++ b/lib/curl_setup.h @@ -642,9 +642,6 @@ #ifdef _WIN32 #define CURL_THREAD_RETURN_T DWORD -#define CURL_WIN_THREADFUNC WINAPI -typedef HANDLE curl_win_thread_handle_t; -#define CURL_WIN_BEGINTHREAD CreateThread #else #define CURL_THREAD_RETURN_T unsigned int #endif diff --git a/lib/curl_threads.c b/lib/curl_threads.c index 015b573d9f..0bacb1a16c 100644 --- a/lib/curl_threads.c +++ b/lib/curl_threads.c @@ -26,12 +26,8 @@ #include -#ifdef USE_THREADS_POSIX -# ifdef HAVE_PTHREAD_H -# include -# endif -#elif defined(USE_THREADS_WIN32) -# include +#if defined(USE_THREADS_POSIX) && defined(HAVE_PTHREAD_H) +#include #endif #include "curl_threads.h" @@ -134,8 +130,7 @@ curl_thread_t Curl_thread_create(CURL_THREAD_RETURN_T (CURL_STDCALL *func) (void *), void *arg) { curl_thread_t t; - curl_win_thread_handle_t thread_handle; - thread_handle = CURL_WIN_BEGINTHREAD(NULL, 0, func, arg, 0, NULL); + HANDLE thread_handle = CreateThread(NULL, 0, func, arg, 0, NULL); t = (curl_thread_t)thread_handle; if((t == 0) || (t == LongToHandle(-1L))) { #ifdef UNDER_CE diff --git a/lib/curl_threads.h b/lib/curl_threads.h index b17a789dd1..fb8b2ad723 100644 --- a/lib/curl_threads.h +++ b/lib/curl_threads.h @@ -35,7 +35,7 @@ # define Curl_mutex_release(m) pthread_mutex_unlock(m) # define Curl_mutex_destroy(m) pthread_mutex_destroy(m) #elif defined(USE_THREADS_WIN32) -# define CURL_STDCALL CURL_WIN_THREADFUNC +# define CURL_STDCALL WINAPI # define curl_mutex_t CRITICAL_SECTION # define curl_thread_t HANDLE # define curl_thread_t_null (HANDLE)0 diff --git a/tests/libtest/lib3026.c b/tests/libtest/lib3026.c index 8c36de3dd0..f5daaf18ae 100644 --- a/tests/libtest/lib3026.c +++ b/tests/libtest/lib3026.c @@ -26,8 +26,7 @@ #define NUM_THREADS 100 #ifdef _WIN32 -#include -static CURL_THREAD_RETURN_T CURL_WIN_THREADFUNC t3026_run_thread(void *ptr) +static CURL_THREAD_RETURN_T WINAPI t3026_run_thread(void *ptr) { CURLcode *result = ptr; @@ -41,7 +40,7 @@ static CURL_THREAD_RETURN_T CURL_WIN_THREADFUNC t3026_run_thread(void *ptr) static CURLcode test_lib3026(const char *URL) { CURLcode results[NUM_THREADS]; - curl_win_thread_handle_t thread_handles[NUM_THREADS]; + HANDLE thread_handles[NUM_THREADS]; unsigned tid_count = NUM_THREADS, i; CURLcode test_failure = CURLE_OK; curl_version_info_data *ver; @@ -56,9 +55,9 @@ static CURLcode test_lib3026(const char *URL) } for(i = 0; i < tid_count; i++) { - curl_win_thread_handle_t th; + HANDLE th; results[i] = CURL_LAST; /* initialize with invalid value */ - th = CURL_WIN_BEGINTHREAD(NULL, 0, t3026_run_thread, &results[i], 0, NULL); + th = CreateThread(NULL, 0, t3026_run_thread, &results[i], 0, NULL); if(!th) { curl_mfprintf(stderr, "%s:%d Couldn't create thread, errno %lu\n", __FILE__, __LINE__, GetLastError()); diff --git a/tests/server/sockfilt.c b/tests/server/sockfilt.c index 8cc9b877d5..61dd6bc986 100644 --- a/tests/server/sockfilt.c +++ b/tests/server/sockfilt.c @@ -412,9 +412,7 @@ struct select_ws_wait_data { HANDLE signal; /* internal event to signal handle trigger */ HANDLE abort; /* internal event to abort waiting threads */ }; -#include -static CURL_THREAD_RETURN_T -CURL_WIN_THREADFUNC select_ws_wait_thread(void *lpParameter) +static CURL_THREAD_RETURN_T WINAPI select_ws_wait_thread(void *lpParameter) { struct select_ws_wait_data *data; HANDLE signal, handle, handles[2]; @@ -559,7 +557,7 @@ CURL_WIN_THREADFUNC select_ws_wait_thread(void *lpParameter) static HANDLE select_ws_wait(HANDLE handle, HANDLE signal, HANDLE abort) { struct select_ws_wait_data *data; - curl_win_thread_handle_t thread; + HANDLE thread; /* allocate internal waiting data structure */ data = malloc(sizeof(struct select_ws_wait_data)); @@ -569,8 +567,7 @@ static HANDLE select_ws_wait(HANDLE handle, HANDLE signal, HANDLE abort) data->abort = abort; /* launch waiting thread */ - thread = CURL_WIN_BEGINTHREAD(NULL, 0, &select_ws_wait_thread, data, 0, - NULL); + thread = CreateThread(NULL, 0, &select_ws_wait_thread, data, 0, NULL); /* free data if thread failed to launch */ if(!thread) { diff --git a/tests/server/util.c b/tests/server/util.c index 2ec5dae624..e26c56d1b6 100644 --- a/tests/server/util.c +++ b/tests/server/util.c @@ -487,9 +487,7 @@ static LRESULT CALLBACK main_window_proc(HWND hwnd, UINT uMsg, } /* Window message queue loop for hidden main window, details see above. */ -#include -static -CURL_THREAD_RETURN_T CURL_WIN_THREADFUNC main_window_loop(void *lpParameter) +static CURL_THREAD_RETURN_T WINAPI main_window_loop(void *lpParameter) { WNDCLASS wc; BOOL ret; @@ -625,10 +623,9 @@ void install_signal_handlers(bool keep_sigalrm) #if !defined(CURL_WINDOWS_UWP) && !defined(UNDER_CE) { - curl_win_thread_handle_t thread; - thread = CURL_WIN_BEGINTHREAD(NULL, 0, &main_window_loop, - (void *)GetModuleHandle(NULL), 0, - &thread_main_id); + HANDLE thread = CreateThread(NULL, 0, &main_window_loop, + (void *)GetModuleHandle(NULL), 0, + &thread_main_id); thread_main_window = (HANDLE)thread; if(!thread_main_window || !thread_main_id) logmsg("cannot start main window loop");