Skip to content

Commit e08ba66

Browse files
authored
Merge pull request #35577 from compnerd/infinite-loop-rather-than-explode
Concurrency: attempt to handle Windows draining
2 parents c216370 + 3c9e76d commit e08ba66

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

stdlib/public/Concurrency/Task.cpp

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -536,17 +536,29 @@ void swift::swift_continuation_logFailedCheck(const char *message) {
536536
}
537537

538538
void swift::swift_task_asyncMainDrainQueue() {
539-
#if !defined(_WIN32)
539+
#if defined(_WIN32)
540+
static void(FAR *pfndispatch_main)(void) = NULL;
541+
542+
if (pfndispatch_main)
543+
return pfndispatch_main();
544+
545+
HMODULE hModule = LoadLibraryW(L"dispatch.dll");
546+
if (hModule == NULL)
547+
abort();
548+
549+
pfndispatch_main =
550+
reinterpret_cast<void (FAR *)(void)>(GetProcAddress(hModule,
551+
"dispatch_main"));
552+
if (pfndispatch_main == NULL)
553+
abort();
554+
555+
pfndispatch_main();
556+
#else
540557
auto runLoop =
541558
reinterpret_cast<void (*)(void)>(dlsym(RTLD_DEFAULT, "CFRunLoopRun"));
542559
if (runLoop)
543560
runLoop();
544561
else
545562
dispatch_main();
546-
#else
547-
// TODO: I don't have a windows box to get this working right now.
548-
// We need to either pull in the CFRunLoop if it's available, or do
549-
// something that will drain the main queue. Exploding for now.
550-
abort();
551563
#endif
552564
}

0 commit comments

Comments
 (0)