17
17
18
18
#include " swift/Runtime/Concurrency.h"
19
19
20
+ #ifdef _WIN32
21
+ // On Windows, an include below triggers an indirect include of minwindef.h
22
+ // which contains a definition of the `max` macro, generating an error in our
23
+ // use of std::max in this file. This define prevents those macros from being
24
+ // defined.
25
+ #define NOMINMAX
26
+ #endif
27
+
20
28
#include " ../CompatibilityOverride/CompatibilityOverride.h"
29
+ #include " ../runtime/ThreadLocalStorage.h"
21
30
#include " swift/Runtime/Atomic.h"
22
31
#include " swift/Runtime/Casting.h"
23
32
#include " swift/Runtime/Once.h"
@@ -177,6 +186,17 @@ class ExecutorTrackingInfo {
177
186
}
178
187
};
179
188
189
+ #ifdef SWIFT_TLS_HAS_RESERVED_PTHREAD_SPECIFIC
190
+ class ActiveTask {
191
+ public:
192
+ static void set (AsyncTask *task) {
193
+ SWIFT_THREAD_SETSPECIFIC (SWIFT_CONCURRENCY_TASK_KEY, task);
194
+ }
195
+ static AsyncTask *get () {
196
+ return (AsyncTask *)SWIFT_THREAD_GETSPECIFIC (SWIFT_CONCURRENCY_TASK_KEY);
197
+ }
198
+ };
199
+ #else
180
200
class ActiveTask {
181
201
// / A thread-local variable pointing to the active tracking
182
202
// / information about the current thread, if any.
@@ -188,12 +208,13 @@ class ActiveTask {
188
208
};
189
209
190
210
// / Define the thread-locals.
191
- SWIFT_RUNTIME_DECLARE_THREAD_LOCAL (
192
- Pointer<ExecutorTrackingInfo>,
193
- ExecutorTrackingInfo::ActiveInfoInThread);
194
211
SWIFT_RUNTIME_DECLARE_THREAD_LOCAL (
195
212
Pointer<AsyncTask>,
196
213
ActiveTask::Value);
214
+ #endif
215
+ SWIFT_RUNTIME_DECLARE_THREAD_LOCAL (
216
+ Pointer<ExecutorTrackingInfo>,
217
+ ExecutorTrackingInfo::ActiveInfoInThread);
197
218
198
219
} // end anonymous namespace
199
220
0 commit comments