From c396f7579245eb601ae37bbdd45f80691e979447 Mon Sep 17 00:00:00 2001 From: Mike Ash Date: Tue, 28 May 2024 17:35:39 -0400 Subject: [PATCH] [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 --- stdlib/public/Concurrency/DispatchGlobalExecutor.inc | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/stdlib/public/Concurrency/DispatchGlobalExecutor.inc b/stdlib/public/Concurrency/DispatchGlobalExecutor.inc index 8010d123dd57e..53ae0eebc9e86 100644 --- a/stdlib/public/Concurrency/DispatchGlobalExecutor.inc +++ b/stdlib/public/Concurrency/DispatchGlobalExecutor.inc @@ -33,6 +33,11 @@ #endif #endif +#if __has_include() +#include +#define SWIFT_CONCURRENCY_HAS_DISPATCH_PRIVATE 1 +#endif + // Ensure that Job's layout is compatible with what Dispatch expects. // Note: MinimalDispatchObjectHeader just has the fields we care about, it is // 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, // Always fall back to plain dispatch_async_f for back-deployed concurrency. #if !defined(SWIFT_CONCURRENCY_BACK_DEPLOYMENT) if (runtime::environment::concurrencyEnableJobDispatchIntegration()) -#if defined(_WIN32) +#if SWIFT_CONCURRENCY_HAS_DISPATCH_PRIVATE + if (SWIFT_RUNTIME_WEAK_CHECK(dispatch_async_swift_job)) + func = SWIFT_RUNTIME_WEAK_USE(dispatch_async_swift_job); +#elif defined(_WIN32) func = reinterpret_cast( GetProcAddress(LoadLibraryW(L"dispatch.dll"), "dispatch_async_swift_job"));