Skip to content

Always use the same TLS context as the runtime for back-deployed concurrency #39556

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
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
26 changes: 20 additions & 6 deletions stdlib/public/BackDeployConcurrency/Exclusivity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,35 @@
//===----------------------------------------------------------------------===//
#include <cinttypes>

#include "swift/Basic/Lazy.h"
#include "swift/Runtime/Exclusivity.h"
#include "swift/Runtime/ThreadLocalStorage.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 {
SwiftTLSContext &SwiftTLSContext::get() {
SwiftTLSContext *ctx = static_cast<SwiftTLSContext *>(
SWIFT_THREAD_GETSPECIFIC(SWIFT_RUNTIME_TLS_KEY));
if (ctx)
return *ctx;

static thread_local SwiftTLSContext TLSContext;
static OnceToken_t setupToken;
SWIFT_ONCE_F(
setupToken,
[](void *) {
pthread_key_init_np(SWIFT_RUNTIME_TLS_KEY, [](void *pointer) {
delete static_cast<SwiftTLSContext *>(pointer);
});
},
nullptr);

} // anonymous namespace

SwiftTLSContext &SwiftTLSContext::get() { return TLSContext; }
ctx = new SwiftTLSContext();
SWIFT_THREAD_SETSPECIFIC(SWIFT_RUNTIME_TLS_KEY, ctx);
return *ctx;
}

// Bring in the concurrency-specific exclusivity code.
#include "../runtime/ConcurrencyExclusivity.inc"
2 changes: 0 additions & 2 deletions test/Concurrency/Runtime/exclusivity.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
// REQUIRES: executable_test
// REQUIRES: concurrency

// rdar://76038845
// REQUIRES: rdar83064974
// REQUIRES: concurrency_runtime
// UNSUPPORTED: back_deployment_runtime

Expand Down