Skip to content

Commit d844d0b

Browse files
authored
Merge pull request #39102 from DougGregor/back-deploy-standalone
Make the back-deployed concurrency dylibs depend only on what's available in older runtimes
2 parents 45b74bd + 6fd85ac commit d844d0b

File tree

7 files changed

+502
-442
lines changed

7 files changed

+502
-442
lines changed

include/swift/Runtime/Exclusivity.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,13 @@ void swift_dumpTrackedAccesses();
7272

7373
#endif
7474

75+
// When building the concurrency library for back deployment, we rename these
76+
// symbols unformly so they don't conflict with the real concurrency library.
77+
#ifdef SWIFT_CONCURRENCY_BACK_DEPLOYMENT
78+
# define swift_task_enterThreadLocalContext swift_task_enterThreadLocalContextBackDeploy
79+
# define swift_task_exitThreadLocalContext swift_task_exitThreadLocalContextBackDeploy
80+
#endif
81+
7582
/// Called when a task inits, resumes and returns control to caller synchronous
7683
/// code to update any exclusivity specific state associated with the task.
7784
///

stdlib/public/BackDeployConcurrency/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,5 +42,6 @@ set(swift_concurrency_install_component back-deployment)
4242
set(swift_concurrency_options
4343
BACK_DEPLOYMENT_LIBRARY 5.5
4444
DARWIN_INSTALL_NAME_DIR "@rpath")
45+
set(swift_concurrency_extra_sources "../BackDeployConcurrency/Exclusivity.cpp")
4546

4647
add_subdirectory(../Concurrency stdlib/public/BackDeployConcurrency)
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
//===--- Exclusivity.cpp - Exclusivity tracking ---------------------------===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See https://swift.org/LICENSE.txt for license information
9+
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
//
13+
// This implements the runtime support for dynamically tracking exclusivity.
14+
//
15+
//===----------------------------------------------------------------------===//
16+
#include <cinttypes>
17+
18+
#include "swift/Runtime/Exclusivity.h"
19+
#include "../runtime/ExclusivityPrivate.h"
20+
#include "../runtime/SwiftTLSContext.h"
21+
22+
using namespace swift;
23+
using namespace swift::runtime;
24+
25+
// Thread-local storage used by the back-deployed concurrency library.
26+
namespace {
27+
28+
static thread_local SwiftTLSContext TLSContext;
29+
30+
} // anonymous namespace
31+
32+
SwiftTLSContext &SwiftTLSContext::get() { return TLSContext; }
33+
34+
// Bring in the concurrency-specific exclusivity code.
35+
#include "../runtime/ConcurrencyExclusivity.inc"

stdlib/public/Concurrency/CMakeLists.txt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@
1010
#
1111
#===----------------------------------------------------------------------===#
1212

13-
set(LLVM_OPTIONAL_SOURCES
14-
${swift_concurrency_objc_sources})
13+
if(NOT swift_concurrency_extra_sources)
14+
set(swift_concurrency_extra_sources)
15+
endif()
1516

1617
if(NOT swift_concurrency_install_component)
1718
set(swift_concurrency_install_component stdlib)
@@ -78,7 +79,7 @@ add_swift_target_library(swift_Concurrency ${SWIFT_STDLIB_LIBRARY_BUILD_TYPES} I
7879
AsyncThrowingStream.swift
7980
AsyncStream.cpp
8081
Deque.swift
81-
${swift_concurrency_objc_sources}
82+
${swift_concurrency_extra_sources}
8283

8384
SWIFT_MODULE_DEPENDS_LINUX Glibc
8485
SWIFT_MODULE_DEPENDS_FREEBSD Glibc

stdlib/public/Concurrency/GlobalExecutor.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -242,8 +242,9 @@ static void initializeDispatchEnqueueFunc(dispatch_queue_t queue, void *obj,
242242
dispatch_qos_class_t qos) {
243243
dispatchEnqueueFuncType func = nullptr;
244244

245-
// Always fall back to plain dispatch_async_f on Windows for now.
246-
#if !defined(_WIN32)
245+
// Always fall back to plain dispatch_async_f on Windows for now, and
246+
// also for back-deployed concurrency.
247+
#if !defined(_WIN32) && !defined(SWIFT_CONCURRENCY_BACK_DEPLOYMENT)
247248
if (runtime::environment::concurrencyEnableJobDispatchIntegration())
248249
func = reinterpret_cast<dispatchEnqueueFuncType>(
249250
dlsym(RTLD_NEXT, "dispatch_async_swift_job"));

0 commit comments

Comments
 (0)