Skip to content

Commit 9502860

Browse files
committed
dispatch: repair the signal thread construction on Windows
Handle the signal thread construction on Windows by using `_beginthreadex` as POSIX threads are not used on Windows. This reapirs the build for Windows.
1 parent d5455e1 commit 9502860

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

src/queue.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7835,6 +7835,15 @@ _dispatch_sig_thread(void *ctxt DISPATCH_UNUSED)
78357835
#endif
78367836
}
78377837

7838+
#if defined(_WIN32)
7839+
static unsigned WINAPI
7840+
_dispatch_sig_thread_thunk(LPVOID lpParameter)
7841+
{
7842+
_dispatch_sig_thread(lpParameter);
7843+
return 0;
7844+
}
7845+
#endif
7846+
78387847
void
78397848
dispatch_main(void)
78407849
{
@@ -7900,6 +7909,7 @@ _dispatch_queue_cleanup2(void)
79007909
// See dispatch_main for call to _dispatch_sig_thread on linux.
79017910
#ifndef __linux__
79027911
if (_dispatch_program_is_probably_callback_driven) {
7912+
#if defined(_POSIX_THREADS)
79037913
pthread_attr_t attr;
79047914
pthread_attr_init(&attr);
79057915
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
@@ -7909,6 +7919,13 @@ _dispatch_queue_cleanup2(void)
79097919
DISPATCH_CLIENT_CRASH(r, "Unable to create signal thread");
79107920
}
79117921
pthread_attr_destroy(&attr);
7922+
#else
7923+
uintptr_t hThread = 0;
7924+
if (unlikely(!(hThread = _beginthreadex(NULL, /* stack_size */ 0, _dispatch_sig_thread_thunk, NULL, STACK_SIZE_PARAM_IS_A_RESERVATION, NULL)))) {
7925+
DISPATCH_CLIENT_CRASH(errno, "unable to create signal thread");
7926+
}
7927+
CloseHandle((HANDLE)hThread);
7928+
#endif
79127929
// this used to be here as a workaround for 6778970
79137930
// but removing it had bincompat fallouts :'(
79147931
sleep(1);

0 commit comments

Comments
 (0)