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
183195class 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);
197206SWIFT_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
0 commit comments