17
17
#ifndef SWIFT_THREADING_IMPL_WIN32_H
18
18
#define SWIFT_THREADING_IMPL_WIN32_H
19
19
20
- #define WIN32_LEAN_AND_MEAN
21
- #define NOMINMAX
22
- #include < windows.h>
23
-
24
- // <windows.h> defines some unhelpful macros
25
- #undef Yield
26
- #undef ERROR
20
+ #include " Win32/Win32Defs.h"
27
21
28
22
#include < atomic>
29
23
@@ -32,7 +26,7 @@ namespace threading_impl {
32
26
33
27
// .. Thread related things ..................................................
34
28
35
- using thread_id = DWORD;
29
+ using thread_id = :: DWORD;
36
30
37
31
inline thread_id thread_get_current () { return ::GetCurrentThreadId (); }
38
32
thread_id thread_get_main ();
@@ -41,31 +35,31 @@ inline bool threads_same(thread_id a, thread_id b) { return a == b; }
41
35
42
36
// .. Mutex support ..........................................................
43
37
44
- using mutex_handle = SRWLOCK;
38
+ using mutex_handle = :: SRWLOCK;
45
39
46
40
inline void mutex_init (mutex_handle &handle, bool checked=false ) {
47
41
handle = SRWLOCK_INIT;
48
42
}
49
43
inline void mutex_destroy (mutex_handle &handle) { }
50
44
51
45
inline void mutex_lock (mutex_handle &handle) {
52
- AcquireSRWLockExclusive (&handle);
46
+ :: AcquireSRWLockExclusive (&handle);
53
47
}
54
48
inline void mutex_unlock (mutex_handle &handle) {
55
- ReleaseSRWLockExclusive (&handle);
49
+ :: ReleaseSRWLockExclusive (&handle);
56
50
}
57
51
inline bool mutex_try_lock (mutex_handle &handle) {
58
- return !!TryAcquireSRWLockExclusive (&handle);
52
+ return !!:: TryAcquireSRWLockExclusive (&handle);
59
53
}
60
54
61
55
inline void mutex_unsafe_lock (mutex_handle &handle) {
62
- AcquireSRWLockExclusive (&handle);
56
+ :: AcquireSRWLockExclusive (&handle);
63
57
}
64
58
inline void mutex_unsafe_unlock (mutex_handle &handle) {
65
- ReleaseSRWLockExclusive (&handle);
59
+ :: ReleaseSRWLockExclusive (&handle);
66
60
}
67
61
68
- using lazy_mutex_handle = SRWLOCK;
62
+ using lazy_mutex_handle = :: SRWLOCK;
69
63
70
64
// We don't need to be lazy here because Win32 has SRWLOCK_INIT.
71
65
inline constexpr lazy_mutex_handle lazy_mutex_initializer () {
@@ -74,20 +68,20 @@ inline constexpr lazy_mutex_handle lazy_mutex_initializer() {
74
68
inline void lazy_mutex_destroy (lazy_mutex_handle &handle) { }
75
69
76
70
inline void lazy_mutex_lock (lazy_mutex_handle &handle) {
77
- AcquireSRWLockExclusive (&handle);
71
+ :: AcquireSRWLockExclusive (&handle);
78
72
}
79
73
inline void lazy_mutex_unlock (lazy_mutex_handle &handle) {
80
- ReleaseSRWLockExclusive (&handle);
74
+ :: ReleaseSRWLockExclusive (&handle);
81
75
}
82
76
inline bool lazy_mutex_try_lock (lazy_mutex_handle &handle) {
83
- return !!TryAcquireSRWLockExclusive (&handle);
77
+ return !!:: TryAcquireSRWLockExclusive (&handle);
84
78
}
85
79
86
80
inline void lazy_mutex_unsafe_lock (lazy_mutex_handle &handle) {
87
- AcquireSRWLockExclusive (&handle);
81
+ :: AcquireSRWLockExclusive (&handle);
88
82
}
89
83
inline void lazy_mutex_unsafe_unlock (lazy_mutex_handle &handle) {
90
- ReleaseSRWLockExclusive (&handle);
84
+ :: ReleaseSRWLockExclusive (&handle);
91
85
}
92
86
93
87
// .. Once ...................................................................
@@ -116,20 +110,20 @@ inline void once_impl(once_t &predicate, void (*fn)(void *), void *context) {
116
110
117
111
#define SWIFT_TLS_DECLARE_DTOR (name ) void NTAPI name (void *)
118
112
119
- using tls_key = DWORD;
120
- using tls_dtor = PFLS_CALLBACK_FUNCTION;
113
+ using tls_key = :: DWORD;
114
+ using tls_dtor = :: PFLS_CALLBACK_FUNCTION;
121
115
122
116
inline bool tls_alloc (tls_key &key, tls_dtor dtor) {
123
- key = FlsAlloc (dtor);
117
+ key = :: FlsAlloc (dtor);
124
118
return key != FLS_OUT_OF_INDEXES;
125
119
}
126
120
127
121
inline void *tls_get (tls_key key) {
128
- return FlsGetValue (key);
122
+ return :: FlsGetValue (key);
129
123
}
130
124
131
125
inline void tls_set (tls_key key, void *value) {
132
- FlsSetValue (key, value);
126
+ :: FlsSetValue (key, value);
133
127
}
134
128
135
129
} // namespace threading_impl
0 commit comments