Skip to content

Make the back-deployed concurrency dylibs depend only on what's available in older runtimes #39102

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 31, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions include/swift/Runtime/Exclusivity.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,13 @@ void swift_dumpTrackedAccesses();

#endif

// When building the concurrency library for back deployment, we rename these
// symbols unformly so they don't conflict with the real concurrency library.
#ifdef SWIFT_CONCURRENCY_BACK_DEPLOYMENT
# define swift_task_enterThreadLocalContext swift_task_enterThreadLocalContextBackDeploy
# define swift_task_exitThreadLocalContext swift_task_exitThreadLocalContextBackDeploy
#endif

/// Called when a task inits, resumes and returns control to caller synchronous
/// code to update any exclusivity specific state associated with the task.
///
Expand Down
1 change: 1 addition & 0 deletions stdlib/public/BackDeployConcurrency/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,6 @@ set(swift_concurrency_install_component back-deployment)
set(swift_concurrency_options
BACK_DEPLOYMENT_LIBRARY 5.5
DARWIN_INSTALL_NAME_DIR "@rpath")
set(swift_concurrency_extra_sources "../BackDeployConcurrency/Exclusivity.cpp")

add_subdirectory(../Concurrency stdlib/public/BackDeployConcurrency)
35 changes: 35 additions & 0 deletions stdlib/public/BackDeployConcurrency/Exclusivity.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
//===--- Exclusivity.cpp - Exclusivity tracking ---------------------------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//
//
// This implements the runtime support for dynamically tracking exclusivity.
//
//===----------------------------------------------------------------------===//
#include <cinttypes>

#include "swift/Runtime/Exclusivity.h"
#include "../runtime/ExclusivityPrivate.h"
#include "../runtime/SwiftTLSContext.h"

using namespace swift;
using namespace swift::runtime;

// Thread-local storage used by the back-deployed concurrency library.
namespace {

static thread_local SwiftTLSContext TLSContext;

} // anonymous namespace

SwiftTLSContext &SwiftTLSContext::get() { return TLSContext; }

// Bring in the concurrency-specific exclusivity code.
#include "../runtime/ConcurrencyExclusivity.inc"
7 changes: 4 additions & 3 deletions stdlib/public/Concurrency/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@
#
#===----------------------------------------------------------------------===#

set(LLVM_OPTIONAL_SOURCES
${swift_concurrency_objc_sources})
if(NOT swift_concurrency_extra_sources)
set(swift_concurrency_extra_sources)
endif()

if(NOT swift_concurrency_install_component)
set(swift_concurrency_install_component stdlib)
Expand Down Expand Up @@ -78,7 +79,7 @@ add_swift_target_library(swift_Concurrency ${SWIFT_STDLIB_LIBRARY_BUILD_TYPES} I
AsyncThrowingStream.swift
AsyncStream.cpp
Deque.swift
${swift_concurrency_objc_sources}
${swift_concurrency_extra_sources}

SWIFT_MODULE_DEPENDS_LINUX Glibc
SWIFT_MODULE_DEPENDS_FREEBSD Glibc
Expand Down
5 changes: 3 additions & 2 deletions stdlib/public/Concurrency/GlobalExecutor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -239,8 +239,9 @@ static void initializeDispatchEnqueueFunc(dispatch_queue_t queue, void *obj,
dispatch_qos_class_t qos) {
dispatchEnqueueFuncType func = nullptr;

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