Skip to content

Commit 472e842

Browse files
committed
Concurrency: avoid CFRunLoopRun on non-Darwin
The CoreFoundation implementation on non-Darwin platforms included in Foundation is not meant to be used as a general purpose CoreFoundation implementation. Since non-Darwin targets do not default to providing a CoreFoundation implementation, we should generally assume that the symbol is not present. This changes the non-Darwin paths to always use `dispatch_main` rather than `CFRunLoopRun`.
1 parent f205b20 commit 472e842

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

stdlib/public/Concurrency/Task.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -554,11 +554,17 @@ void swift::swift_task_asyncMainDrainQueue() {
554554

555555
pfndispatch_main();
556556
#else
557+
// CFRunLoop is not available on non-Darwin targets. Foundation has an
558+
// implementation, but CoreFoundation is not meant to be exposed. We can only
559+
// assume the existence of `CFRunLoopRun` on Darwin platforms, where the
560+
// system provides an implementation of CoreFoundation.
561+
#if defined(__APPLE__)
557562
auto runLoop =
558563
reinterpret_cast<void (*)(void)>(dlsym(RTLD_DEFAULT, "CFRunLoopRun"));
559564
if (runLoop)
560-
runLoop();
561-
else
565+
return runLoop();
566+
#endif
567+
562568
dispatch_main();
563569
#endif
564570
}

0 commit comments

Comments
 (0)