Skip to content

Commit 326f18d

Browse files
committed
Runtimes: detect the existence of dispatch_async_swift_job
This function is used by the executor to help schedule the async job. While not currently available on Windows on main, this allows correctly handling the presence of the symbol for static linking.
1 parent d8a12e9 commit 326f18d

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

Runtimes/Core/Concurrency/dispatch.cmake

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11

22
find_package(dispatch QUIET REQUIRED)
33

4+
check_symbol_exists("dispatch_async_swift_job" "dispatch/private.h"
5+
SwiftConcurrency_HAS_DISPATCH_ASYNC_SWIFT_JOB)
6+
47
target_sources(swift_Concurrency PRIVATE
58
DispatchGlobalExecutor.cpp
69
DispatchExecutor.swift
710
CFExecutor.swift
811
ExecutorImpl.swift)
912
target_compile_definitions(swift_Concurrency PRIVATE
13+
$<$<BOOL:${SwiftConcurrency_HAS_DISPATCH_ASYNC_SWIFT_JOB}>:-DSwiftConcurrency_HAS_DISPATCH_ASYNC_SWIFT_JOB=1>
1014
$<$<COMPILE_LANGUAGE:C,CXX>:-DSWIFT_CONCURRENCY_USES_DISPATCH=1>)
1115
target_compile_options(swift_Concurrency PRIVATE
1216
$<$<COMPILE_LANGUAGE:Swift>:-DSWIFT_CONCURRENCY_USES_DISPATCH>

stdlib/public/Concurrency/DispatchGlobalExecutor.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,13 +103,15 @@ static void initializeDispatchEnqueueFunc(dispatch_queue_t queue, void *obj,
103103
if (SWIFT_RUNTIME_WEAK_CHECK(dispatch_async_swift_job))
104104
func = SWIFT_RUNTIME_WEAK_USE(dispatch_async_swift_job);
105105
#elif defined(_WIN32)
106+
#if SwiftConcurrency_HAS_DISPATCH_ASYNC_SWIFT_JOB
106107
#if defined(dispatch_STATIC)
107108
func = dispatch_async_swift_job;
108109
#else
109110
func = function_cast<dispatchEnqueueFuncType>(
110111
GetProcAddress(LoadLibraryW(L"dispatch.dll"),
111112
"dispatch_async_swift_job"));
112113
#endif
114+
#endif
113115
#else
114116
func = function_cast<dispatchEnqueueFuncType>(
115117
dlsym(RTLD_NEXT, "dispatch_async_swift_job"));

0 commit comments

Comments
 (0)