try moving win32 to CreateThread() API 2

This commit is contained in:
Viktor Szakats 2025-09-03 23:10:34 +02:00
parent 7b0a826158
commit 01385ef1e9
No known key found for this signature in database
GPG key ID: B5ABD165E2AEF201
6 changed files with 15 additions and 30 deletions

View file

@ -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

View file

@ -26,12 +26,8 @@
#include <curl/curl.h>
#ifdef USE_THREADS_POSIX
# ifdef HAVE_PTHREAD_H
# include <pthread.h>
# endif
#elif defined(USE_THREADS_WIN32)
# include <process.h>
#if defined(USE_THREADS_POSIX) && defined(HAVE_PTHREAD_H)
#include <pthread.h>
#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

View file

@ -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

View file

@ -26,8 +26,7 @@
#define NUM_THREADS 100
#ifdef _WIN32
#include <process.h>
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());

View file

@ -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 <process.h>
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) {

View file

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