Skip to content

Commit 8c5d383

Browse files
authored
Concurrency: add Windows support to SWIFT_TASK_PRINTF_DEBUG
`pthread_self` is not portable to all platforms. Introduce a `_swift_get_current_thread_id` to abstract over accessing the current thread ID. On Windows, the thread ID and thread handle are two separate entities, unlike POSIX threads which treats them the same.
1 parent 5e0d32b commit 8c5d383

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

stdlib/public/Concurrency/TaskPrivate.h

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,16 @@
2727

2828
#include "../runtime/StackAllocator.h"
2929

30+
#if HAVE_PTHREAD_H
31+
#include <pthread.h>
32+
#endif
33+
#if defined(_WIN32)
34+
#define WIN32_LEAN_AND_MEAN
35+
#define VC_EXTRA_LEAN
36+
#define NOMINMAX
37+
#include <Windows.h>
38+
#endif
39+
3040
namespace swift {
3141

3242
// Set to 1 to enable helpful debug spew to stderr
@@ -41,6 +51,20 @@ namespace swift {
4151
#define SWIFT_TASK_DEBUG_LOG(fmt, ...) (void)0
4252
#endif
4353

54+
#if defined(_WIN32)
55+
using ThreadID = decltype(GetCurrentThreadId());
56+
#else
57+
using ThreadID = decltype(pthread_self());
58+
#endif
59+
60+
inline ThreadID _swift_get_thread_id() {
61+
#if defined(_WIN32)
62+
return GetCurrentThreadId();
63+
#else
64+
return pthread_self();
65+
#endif
66+
}
67+
4468
class AsyncTask;
4569
class TaskGroup;
4670

0 commit comments

Comments
 (0)