Skip to content

Commit d5808b0

Browse files
authored
Merge pull request swiftlang#37136 from fredriss/task-use-static-tsd
[Concurrency] Use a stable TSD on Darwin to store the current Task
2 parents 7f537b4 + 8f1a73c commit d5808b0

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

stdlib/public/Concurrency/Actor.cpp

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "swift/Runtime/Concurrency.h"
1919

2020
#include "../CompatibilityOverride/CompatibilityOverride.h"
21+
#include "../runtime/ThreadLocalStorage.h"
2122
#include "swift/Runtime/Atomic.h"
2223
#include "swift/Runtime/Casting.h"
2324
#include "swift/Runtime/Once.h"
@@ -180,6 +181,17 @@ class ExecutorTrackingInfo {
180181
}
181182
};
182183

184+
#ifdef SWIFT_TLS_HAS_RESERVED_PTHREAD_SPECIFIC
185+
class ActiveTask {
186+
public:
187+
static void set(AsyncTask *task) {
188+
SWIFT_THREAD_SETSPECIFIC(SWIFT_CONCURRENCY_TASK_KEY, task);
189+
}
190+
static AsyncTask *get() {
191+
return (AsyncTask *)SWIFT_THREAD_GETSPECIFIC(SWIFT_CONCURRENCY_TASK_KEY);
192+
}
193+
};
194+
#else
183195
class ActiveTask {
184196
/// A thread-local variable pointing to the active tracking
185197
/// information about the current thread, if any.
@@ -191,12 +203,13 @@ class ActiveTask {
191203
};
192204

193205
/// Define the thread-locals.
194-
SWIFT_RUNTIME_DECLARE_THREAD_LOCAL(
195-
Pointer<ExecutorTrackingInfo>,
196-
ExecutorTrackingInfo::ActiveInfoInThread);
197206
SWIFT_RUNTIME_DECLARE_THREAD_LOCAL(
198207
Pointer<AsyncTask>,
199208
ActiveTask::Value);
209+
#endif
210+
SWIFT_RUNTIME_DECLARE_THREAD_LOCAL(
211+
Pointer<ExecutorTrackingInfo>,
212+
ExecutorTrackingInfo::ActiveInfoInThread);
200213

201214
} // end anonymous namespace
202215

stdlib/public/runtime/ThreadLocalStorage.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,15 @@ extern "C" int pthread_key_init_np(int key, void (*destructor)(void *));
4545
# ifndef __PTK_FRAMEWORK_SWIFT_KEY2
4646
# define __PTK_FRAMEWORK_SWIFT_KEY2 102
4747
# endif
48+
# ifndef __PTK_FRAMEWORK_SWIFT_KEY3
49+
# define __PTK_FRAMEWORK_SWIFT_KEY3 103
50+
# endif
4851

4952

5053
# define SWIFT_RUNTIME_TLS_KEY __PTK_FRAMEWORK_SWIFT_KEY0
5154
# define SWIFT_STDLIB_TLS_KEY __PTK_FRAMEWORK_SWIFT_KEY1
5255
# define SWIFT_COMPATIBILITY_50_TLS_KEY __PTK_FRAMEWORK_SWIFT_KEY2
56+
# define SWIFT_CONCURRENCY_TASK_KEY __PTK_FRAMEWORK_SWIFT_KEY3
5357

5458
#endif
5559

0 commit comments

Comments
 (0)