Skip to content

Commit c396f75

Browse files
committed
[Concurrency] Reference dispatch_async_swift_job directly when the header is available.
Only use dlsym when we don't have the header, since it's an unnecessary performance hit. rdar://118465481
1 parent 511e619 commit c396f75

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

stdlib/public/Concurrency/DispatchGlobalExecutor.inc

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@
3333
#endif
3434
#endif
3535

36+
#if __has_include(<dispatch/private.h>)
37+
#include <dispatch/private.h>
38+
#define SWIFT_CONCURRENCY_HAS_DISPATCH_PRIVATE 1
39+
#endif
40+
3641
// Ensure that Job's layout is compatible with what Dispatch expects.
3742
// Note: MinimalDispatchObjectHeader just has the fields we care about, it is
3843
// not complete and should not be used for anything other than these asserts.
@@ -89,7 +94,10 @@ static void initializeDispatchEnqueueFunc(dispatch_queue_t queue, void *obj,
8994
// Always fall back to plain dispatch_async_f for back-deployed concurrency.
9095
#if !defined(SWIFT_CONCURRENCY_BACK_DEPLOYMENT)
9196
if (runtime::environment::concurrencyEnableJobDispatchIntegration())
92-
#if defined(_WIN32)
97+
#if SWIFT_CONCURRENCY_HAS_DISPATCH_PRIVATE
98+
if (SWIFT_RUNTIME_WEAK_CHECK(dispatch_async_swift_job))
99+
func = SWIFT_RUNTIME_WEAK_USE(dispatch_async_swift_job);
100+
#elif defined(_WIN32)
93101
func = reinterpret_cast<dispatchEnqueueFuncType>(
94102
GetProcAddress(LoadLibraryW(L"dispatch.dll"),
95103
"dispatch_async_swift_job"));

0 commit comments

Comments
 (0)