|
35 | 35 | #include "swift/Threading/Once.h"
|
36 | 36 | #include "swift/Threading/Mutex.h"
|
37 | 37 | #include "swift/Threading/ThreadLocalStorage.h"
|
| 38 | +#include "swift/Threading/Thread.h" |
38 | 39 | #include "swift/ABI/Task.h"
|
39 | 40 | #include "swift/ABI/Actor.h"
|
40 | 41 | #include "swift/Basic/ListMerger.h"
|
|
67 | 68 | #include <sys/syscall.h>
|
68 | 69 | #endif
|
69 | 70 |
|
70 |
| -#if defined(_POSIX_THREADS) |
71 |
| -#include <pthread.h> |
72 |
| - |
73 |
| -// Only use __has_include since HAVE_PTHREAD_NP_H is not provided. |
74 |
| -#if __has_include(<pthread_np.h>) |
75 |
| -#include <pthread_np.h> |
76 |
| -#endif |
77 |
| -#endif |
78 |
| - |
79 |
| -#if defined(_WIN32) |
80 |
| -#include <io.h> |
81 |
| -#include <handleapi.h> |
82 |
| -#include <processthreadsapi.h> |
83 |
| -#endif |
84 |
| - |
85 | 71 | #if SWIFT_OBJC_INTEROP
|
86 | 72 | extern "C" void *objc_autoreleasePoolPush();
|
87 | 73 | extern "C" void objc_autoreleasePoolPop(void *);
|
@@ -278,29 +264,13 @@ static ExecutorRef swift_task_getCurrentExecutorImpl() {
|
278 | 264 | return result;
|
279 | 265 | }
|
280 | 266 |
|
281 |
| -#if defined(_WIN32) |
282 |
| -static HANDLE __initialPthread = INVALID_HANDLE_VALUE; |
283 |
| -#endif |
284 |
| - |
285 | 267 | /// Determine whether we are currently executing on the main thread
|
286 | 268 | /// independently of whether we know that we are on the main actor.
|
287 | 269 | static bool isExecutingOnMainThread() {
|
288 | 270 | #if SWIFT_STDLIB_SINGLE_THREADED_CONCURRENCY
|
289 | 271 | return true;
|
290 |
| -#elif defined(__linux__) |
291 |
| - return syscall(SYS_gettid) == getpid(); |
292 |
| -#elif defined(_WIN32) |
293 |
| - if (__initialPthread == INVALID_HANDLE_VALUE) { |
294 |
| - DuplicateHandle(GetCurrentProcess(), GetCurrentThread(), |
295 |
| - GetCurrentProcess(), &__initialPthread, 0, FALSE, |
296 |
| - DUPLICATE_SAME_ACCESS); |
297 |
| - } |
298 |
| - |
299 |
| - return __initialPthread == GetCurrentThread(); |
300 |
| -#elif defined(__wasi__) |
301 |
| - return true; |
302 | 272 | #else
|
303 |
| - return pthread_main_np() == 1; |
| 273 | + return Thread::onMainThread(); |
304 | 274 | #endif
|
305 | 275 | }
|
306 | 276 |
|
|
0 commit comments