Skip to content

Commit 3c9e76d

Browse files
committed
Concurrency: attempt to handle Windows draining
Rather than just simply invoking abort on Windows, attempt to load dispatch and execute the main loop by looking up `dispatch_main` in the module. Assuming that dispatch was used already, the `LoadLibraryW` will provide the handle to the module currently mapped in. This still is not correct, since we do not link to libdispatch, so we cannot have invoked any dispatch queuing methods. However, this is better than the previous behaviour of simply aborting. This resolves the symptom in SR-14086, but not the underlying problem.
1 parent af7f1e6 commit 3c9e76d

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)