← Commit list

1c49f2f26d

Viktor Szakats
Viktor Szakats
2025-09-20
FAILED Duration: 330s

Subject

windows: replace `_beginthreadex()` with `CreateThread()`

Binary

No binary (build failed)

Architecture & Compiler Flags

Architecture: x86_64-linux-gnu Compiler: gcc (Ubuntu 11.4.0-1ubuntu1~22.04.3) 11.4.0

—

Build Log

(log yok)

Commit Diff GitHub →

lib/curl_threads.c+5 -21
@@ -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"
@@ -105,20 +101,8 @@ int Curl_thread_join(curl_thread_t *hnd)
curl_thread_t Curl_thread_create(CURL_THREAD_RETURN_T
(CURL_STDCALL *func) (void *), void *arg)
{
-#if defined(CURL_WINDOWS_UWP) || defined(UNDER_CE)
- typedef HANDLE curl_win_thread_handle_t;
-#else
- typedef uintptr_t curl_win_thread_handle_t;
-#endif
- curl_thread_t t;
- curl_win_thread_handle_t thread_handle;
-#if defined(CURL_WINDOWS_UWP) || defined(UNDER_CE)
- thread_handle = CreateThread(NULL, 0, func, arg, 0, NULL);
-#else
- thread_handle = _beginthreadex(NULL, 0, func, arg, 0, NULL);
-#endif
- t = (curl_thread_t)thread_handle;
- if((t == 0) || (t == LongToHandle(-1L))) {
+ curl_thread_t t = CreateThread(NULL, 0, func, arg, 0, NULL);
+ if(!t) {
#ifdef UNDER_CE
DWORD gle = GetLastError();
/* !checksrc! disable ERRNOVAR 1 */
@@ -142,7 +126,7 @@ void Curl_thread_destroy(curl_thread_t *hnd)
int Curl_thread_join(curl_thread_t *hnd)
{
-#if !defined(_WIN32_WINNT) || (_WIN32_WINNT < _WIN32_WINNT_VISTA)
+#ifdef UNDER_CE
int ret = (WaitForSingleObject(*hnd, INFINITE) == WAIT_OBJECT_0);
#else
int ret = (WaitForSingleObjectEx(*hnd, INFINITE, FALSE) == WAIT_OBJECT_0);
lib/curl_threads.h+3 -9
@@ -26,6 +26,7 @@
#include "curl_setup.h"
#ifdef USE_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 *
@@ -35,7 +36,8 @@
# 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 __stdcall
+# define CURL_THREAD_RETURN_T DWORD
+# define CURL_STDCALL WINAPI
# define curl_mutex_t CRITICAL_SECTION
# define curl_thread_t HANDLE
# define curl_thread_t_null (HANDLE)0
@@ -47,14 +49,6 @@
# define Curl_mutex_acquire(m) EnterCriticalSection(m)
# define Curl_mutex_release(m) LeaveCriticalSection(m)
# define Curl_mutex_destroy(m) DeleteCriticalSection(m)
-#else
-# define CURL_STDCALL
-#endif
-
-#if defined(CURL_WINDOWS_UWP) || defined(UNDER_CE)
-#define CURL_THREAD_RETURN_T DWORD
-#else
-#define CURL_THREAD_RETURN_T unsigned int
#endif
#if defined(USE_THREADS_POSIX) || defined(USE_THREADS_WIN32)
tests/libtest/lib3026.c+5 -19
@@ -26,12 +26,7 @@
#define NUM_THREADS 100
#ifdef _WIN32
-#if defined(CURL_WINDOWS_UWP) || defined(UNDER_CE)
-static DWORD WINAPI t3026_run_thread(LPVOID ptr)
-#else
-#include <process.h>
-static unsigned int WINAPI t3026_run_thread(void *ptr)
-#endif
+static DWORD WINAPI t3026_run_thread(void *ptr)
{
CURLcode *result = ptr;
@@ -44,13 +39,8 @@ static unsigned int WINAPI t3026_run_thread(void *ptr)
static CURLcode test_lib3026(const char *URL)
{
-#if defined(CURL_WINDOWS_UWP) || defined(UNDER_CE)
- typedef HANDLE curl_win_thread_handle_t;
-#else
- typedef uintptr_t curl_win_thread_handle_t;
-#endif
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;
@@ -65,13 +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 */
-#if defined(CURL_WINDOWS_UWP) || defined(UNDER_CE)
th = CreateThread(NULL, 0, t3026_run_thread, &results[i], 0, NULL);
-#else
- th = _beginthreadex(NULL, 0, t3026_run_thread, &results[i], 0, NULL);
-#endif
if(!th) {
curl_mfprintf(stderr, "%s:%d Couldn't create thread, errno %lu\n",
__FILE__, __LINE__, GetLastError());
@@ -84,8 +70,8 @@ static CURLcode test_lib3026(const char *URL)
cleanup:
for(i = 0; i < tid_count; i++) {
- WaitForSingleObject((HANDLE)thread_handles[i], INFINITE);
- CloseHandle((HANDLE)thread_handles[i]);
+ WaitForSingleObject(thread_handles[i], INFINITE);
+ CloseHandle(thread_handles[i]);
if(results[i] != CURLE_OK) {
curl_mfprintf(stderr, "%s:%d thread[%u]: curl_global_init() failed,"
"with code %d (%s)\n", __FILE__, __LINE__,
tests/libtest/lib3207.c+4 -0
@@ -68,7 +68,11 @@ static size_t write_memory_callback(char *contents, size_t size,
return realsize;
}
+#if defined(USE_THREADS_POSIX) || defined(USE_THREADS_WIN32)
static CURL_THREAD_RETURN_T CURL_STDCALL test_thread(void *ptr)
+#else
+static unsigned int test_thread(void *ptr)
+#endif
{
struct Ctx *ctx = (struct Ctx *)ptr;
CURLcode res = CURLE_OK;
tests/server/sockfilt.c+5 -6
@@ -412,8 +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 unsigned int WINAPI select_ws_wait_thread(void *lpParameter)
+static DWORD WINAPI select_ws_wait_thread(void *lpParameter)
{
struct select_ws_wait_data *data;
HANDLE signal, handle, handles[2];
@@ -557,25 +556,25 @@ static unsigned int WINAPI select_ws_wait_thread(void *lpParameter)
static HANDLE select_ws_wait(HANDLE handle, HANDLE signal, HANDLE abort)
{
- typedef uintptr_t curl_win_thread_handle_t;
struct select_ws_wait_data *data;
- curl_win_thread_handle_t thread;
/* allocate internal waiting data structure */
data = malloc(sizeof(struct select_ws_wait_data));
if(data) {
+ HANDLE thread;
+
data->handle = handle;
data->signal = signal;
data->abort = abort;
/* launch waiting thread */
- thread = _beginthreadex(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) {
free(data);
}
- return (HANDLE)thread;
+ return thread;
}
return NULL;
}
tests/server/util.c+7 -13
@@ -350,7 +350,7 @@ static SIGHANDLER_T old_sigbreak_handler = SIG_ERR;
#endif
#if defined(_WIN32) && !defined(CURL_WINDOWS_UWP) && !defined(UNDER_CE)
-static unsigned int thread_main_id = 0;
+static DWORD thread_main_id = 0;
static HANDLE thread_main_window = NULL;
static HWND hidden_main_window = NULL;
#endif
@@ -487,8 +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 unsigned int WINAPI main_window_loop(void *lpParameter)
+static DWORD WINAPI main_window_loop(void *lpParameter)
{
WNDCLASS wc;
BOOL ret;
@@ -509,7 +508,7 @@ static unsigned int WINAPI main_window_loop(void *lpParameter)
CW_USEDEFAULT, CW_USEDEFAULT,
CW_USEDEFAULT, CW_USEDEFAULT,
(HWND)NULL, (HMENU)NULL,
- wc.hInstance, (LPVOID)NULL);
+ wc.hInstance, NULL);
if(!hidden_main_window) {
win32_perror("CreateWindowEx failed");
return (DWORD)-1;
@@ -623,15 +622,10 @@ void install_signal_handlers(bool keep_sigalrm)
#endif
#if !defined(CURL_WINDOWS_UWP) && !defined(UNDER_CE)
- {
- typedef uintptr_t curl_win_thread_handle_t;
- curl_win_thread_handle_t thread;
- thread = _beginthreadex(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");
- }
+ thread_main_window = CreateThread(NULL, 0, &main_window_loop,
+ GetModuleHandle(NULL), 0, &thread_main_id);
+ if(!thread_main_window || !thread_main_id)
+ logmsg("cannot start main window loop");
#endif
#endif
}