Skip to content

Commit 2747285

Browse files
committed
Always use the same TLS context as the runtime for back-deployed concurrency
The exclusivity checking support for concurrency relies on having access to the thread-local set of active memory accesses. Teach the back-deployed concurrency library to use the same TLS context as the runtime, which fortunately hasn't change. This fixes the concurrency exclusivity-checking test in back-deployed configurations that's tracked by rdar://83064974.
1 parent 124b5cc commit 2747285

File tree

2 files changed

+20
-8
lines changed

2 files changed

+20
-8
lines changed

stdlib/public/BackDeployConcurrency/Exclusivity.cpp

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,35 @@
1515
//===----------------------------------------------------------------------===//
1616
#include <cinttypes>
1717

18+
#include "swift/Basic/Lazy.h"
1819
#include "swift/Runtime/Exclusivity.h"
20+
#include "swift/Runtime/ThreadLocalStorage.h"
1921
#include "../runtime/ExclusivityPrivate.h"
2022
#include "../runtime/SwiftTLSContext.h"
2123

2224
using namespace swift;
2325
using namespace swift::runtime;
2426

25-
// Thread-local storage used by the back-deployed concurrency library.
26-
namespace {
27+
SwiftTLSContext &SwiftTLSContext::get() {
28+
SwiftTLSContext *ctx = static_cast<SwiftTLSContext *>(
29+
SWIFT_THREAD_GETSPECIFIC(SWIFT_RUNTIME_TLS_KEY));
30+
if (ctx)
31+
return *ctx;
2732

28-
static thread_local SwiftTLSContext TLSContext;
33+
static OnceToken_t setupToken;
34+
SWIFT_ONCE_F(
35+
setupToken,
36+
[](void *) {
37+
pthread_key_init_np(SWIFT_RUNTIME_TLS_KEY, [](void *pointer) {
38+
delete static_cast<SwiftTLSContext *>(pointer);
39+
});
40+
},
41+
nullptr);
2942

30-
} // anonymous namespace
31-
32-
SwiftTLSContext &SwiftTLSContext::get() { return TLSContext; }
43+
ctx = new SwiftTLSContext();
44+
SWIFT_THREAD_SETSPECIFIC(SWIFT_RUNTIME_TLS_KEY, ctx);
45+
return *ctx;
46+
}
3347

3448
// Bring in the concurrency-specific exclusivity code.
3549
#include "../runtime/ConcurrencyExclusivity.inc"

test/Concurrency/Runtime/exclusivity.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
// REQUIRES: executable_test
44
// REQUIRES: concurrency
55

6-
// rdar://76038845
7-
// REQUIRES: rdar83064974
86
// REQUIRES: concurrency_runtime
97
// UNSUPPORTED: back_deployment_runtime
108

0 commit comments

Comments
 (0)