mirror of
https://github.com/curl/curl.git
synced 2026-08-25 01:23:31 +03:00
tests: avoid CreateThread if _beginthreadex is available
CreateThread is not threadsafe if mixed with CRT calls. _beginthreadex on the other hand can be mixed with CRT. Reviewed-by: Marcel Raad Closes #9705
This commit is contained in:
parent
3f5a7975a5
commit
81094cb492
3 changed files with 65 additions and 14 deletions
|
|
@ -406,7 +406,12 @@ struct select_ws_wait_data {
|
|||
HANDLE signal; /* internal event to signal handle trigger */
|
||||
HANDLE abort; /* internal event to abort waiting threads */
|
||||
};
|
||||
#ifdef _WIN32_WCE
|
||||
static DWORD WINAPI select_ws_wait_thread(LPVOID lpParameter)
|
||||
#else
|
||||
#include <process.h>
|
||||
static unsigned int WINAPI select_ws_wait_thread(void *lpParameter)
|
||||
#endif
|
||||
{
|
||||
struct select_ws_wait_data *data;
|
||||
HANDLE signal, handle, handles[2];
|
||||
|
|
@ -549,8 +554,15 @@ static DWORD WINAPI select_ws_wait_thread(LPVOID lpParameter)
|
|||
}
|
||||
static HANDLE select_ws_wait(HANDLE handle, HANDLE signal, HANDLE abort)
|
||||
{
|
||||
#ifdef _WIN32_WCE
|
||||
typedef HANDLE curl_win_thread_handle_t;
|
||||
#elif defined(__MINGW32__) && !defined(__MINGW64_VERSION_MAJOR)
|
||||
typedef unsigned long curl_win_thread_handle_t;
|
||||
#else
|
||||
typedef uintptr_t curl_win_thread_handle_t;
|
||||
#endif
|
||||
struct select_ws_wait_data *data;
|
||||
HANDLE thread = NULL;
|
||||
curl_win_thread_handle_t thread;
|
||||
|
||||
/* allocate internal waiting data structure */
|
||||
data = malloc(sizeof(struct select_ws_wait_data));
|
||||
|
|
@ -560,17 +572,19 @@ static HANDLE select_ws_wait(HANDLE handle, HANDLE signal, HANDLE abort)
|
|||
data->abort = abort;
|
||||
|
||||
/* launch waiting thread */
|
||||
thread = CreateThread(NULL, 0,
|
||||
&select_ws_wait_thread,
|
||||
data, 0, NULL);
|
||||
#ifdef _WIN32_WCE
|
||||
thread = CreateThread(NULL, 0, &select_ws_wait_thread, data, 0, NULL);
|
||||
#else
|
||||
thread = _beginthreadex(NULL, 0, &select_ws_wait_thread, data, 0, NULL);
|
||||
#endif
|
||||
|
||||
/* free data if thread failed to launch */
|
||||
if(!thread) {
|
||||
free(data);
|
||||
}
|
||||
return (HANDLE)thread;
|
||||
}
|
||||
|
||||
return thread;
|
||||
return NULL;
|
||||
}
|
||||
struct select_ws_data {
|
||||
int fd; /* provided file descriptor (indexed by nfd) */
|
||||
|
|
|
|||
|
|
@ -521,7 +521,11 @@ static SIGHANDLER_T old_sigbreak_handler = SIG_ERR;
|
|||
#endif
|
||||
|
||||
#ifdef WIN32
|
||||
#ifdef _WIN32_WCE
|
||||
static DWORD thread_main_id = 0;
|
||||
#else
|
||||
static unsigned int thread_main_id = 0;
|
||||
#endif
|
||||
static HANDLE thread_main_window = NULL;
|
||||
static HWND hidden_main_window = NULL;
|
||||
#endif
|
||||
|
|
@ -624,7 +628,12 @@ static LRESULT CALLBACK main_window_proc(HWND hwnd, UINT uMsg,
|
|||
}
|
||||
/* Window message queue loop for hidden main window, details see above.
|
||||
*/
|
||||
#ifdef _WIN32_WCE
|
||||
static DWORD WINAPI main_window_loop(LPVOID lpParameter)
|
||||
#else
|
||||
#include <process.h>
|
||||
static unsigned int WINAPI main_window_loop(void *lpParameter)
|
||||
#endif
|
||||
{
|
||||
WNDCLASS wc;
|
||||
BOOL ret;
|
||||
|
|
@ -705,6 +714,14 @@ static SIGHANDLER_T set_signal(int signum, SIGHANDLER_T handler,
|
|||
void install_signal_handlers(bool keep_sigalrm)
|
||||
{
|
||||
#ifdef WIN32
|
||||
#ifdef _WIN32_WCE
|
||||
typedef HANDLE curl_win_thread_handle_t;
|
||||
#elif defined(__MINGW32__) && !defined(__MINGW64_VERSION_MAJOR)
|
||||
typedef unsigned long curl_win_thread_handle_t;
|
||||
#else
|
||||
typedef uintptr_t curl_win_thread_handle_t;
|
||||
#endif
|
||||
curl_win_thread_handle_t thread;
|
||||
/* setup windows exit event before any signal can trigger */
|
||||
exit_event = CreateEvent(NULL, TRUE, FALSE, NULL);
|
||||
if(!exit_event)
|
||||
|
|
@ -753,10 +770,14 @@ void install_signal_handlers(bool keep_sigalrm)
|
|||
#ifdef WIN32
|
||||
if(!SetConsoleCtrlHandler(ctrl_event_handler, TRUE))
|
||||
logmsg("cannot install CTRL event handler");
|
||||
thread_main_window = CreateThread(NULL, 0,
|
||||
&main_window_loop,
|
||||
(LPVOID)GetModuleHandle(NULL),
|
||||
0, &thread_main_id);
|
||||
#ifdef _WIN32_WCE
|
||||
thread = CreateThread(NULL, 0, &main_window_loop,
|
||||
(LPVOID)GetModuleHandle(NULL), 0, &thread_main_id);
|
||||
#else
|
||||
thread = _beginthreadex(NULL, 0, &main_window_loop,
|
||||
(void *)GetModuleHandle(NULL), 0, &thread_main_id);
|
||||
#endif
|
||||
thread_main_window = (HANDLE)thread;
|
||||
if(!thread_main_window || !thread_main_id)
|
||||
logmsg("cannot start main window loop");
|
||||
#endif
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue