|
15 | 15 | #include <cmath>
|
16 | 16 | #if defined(_WIN32)
|
17 | 17 | #include <io.h>
|
| 18 | +#define WIN32_LEAN_AND_MEAN |
| 19 | +#include <Windows.h> |
18 | 20 | #else
|
19 | 21 | #include <unistd.h>
|
20 |
| -#endif |
21 | 22 | #include <pthread.h>
|
| 23 | +#endif |
22 | 24 |
|
23 | 25 | #include <stdlib.h>
|
24 | 26 | #include <stdio.h>
|
@@ -60,7 +62,7 @@ __swift_size_t swift::_swift_stdlib_strlen(const char *s) {
|
60 | 62 |
|
61 | 63 | SWIFT_RUNTIME_STDLIB_INTERFACE
|
62 | 64 | __swift_size_t swift::_swift_stdlib_strlen_unsigned(const unsigned char *s) {
|
63 |
| - return strlen((char *)s); |
| 65 | + return strlen(reinterpret_cast<const char *>(s)); |
64 | 66 | }
|
65 | 67 |
|
66 | 68 | SWIFT_RUNTIME_STDLIB_INTERFACE
|
@@ -98,34 +100,57 @@ int swift::_swift_stdlib_close(int fd) {
|
98 | 100 | #endif
|
99 | 101 | }
|
100 | 102 |
|
101 |
| -// Guard compilation on the typedef for __swift_pthread_key_t in LibcShims.h |
| 103 | +#if defined(_WIN32) |
| 104 | +static_assert(std::is_same<__swift_thread_key_t, DWORD>::value, |
| 105 | + "__swift_thread_key_t is not a DWORD"); |
| 106 | + |
| 107 | +SWIFT_RUNTIME_STDLIB_INTERFACE |
| 108 | +int |
| 109 | +swift::_swift_stdlib_thread_key_create(__swift_thread_key_t * _Nonnull key, |
| 110 | + void (* _Nullable destructor)(void *)) { |
| 111 | + // TODO(compnerd) account for x86 CC violation (__stdcall) |
| 112 | + *key = FlsAlloc(reinterpret_cast<PFLS_CALLBACK_FUNCTION>(destructor)); |
| 113 | + return *key != FLS_OUT_OF_INDEXES; |
| 114 | +} |
| 115 | + |
| 116 | +SWIFT_RUNTIME_STDLIB_INTERFACE |
| 117 | +void * _Nullable |
| 118 | +swift::_swift_stdlib_thread_getspecific(__swift_thread_key_t key) { |
| 119 | + return FlsGetValue(key); |
| 120 | +} |
| 121 | + |
| 122 | +SWIFT_RUNTIME_STDLIB_INTERFACE |
| 123 | +int swift::_swift_stdlib_thread_setspecific(__swift_thread_key_t key, |
| 124 | + const void * _Nullable value) { |
| 125 | + return FlsSetValue(key, const_cast<void *>(value)) == TRUE; |
| 126 | +} |
| 127 | +#else |
| 128 | +// Guard compilation on the typedef for __swift_thread_key_t in LibcShims.h |
102 | 129 | // being identical to the platform's pthread_key_t
|
103 |
| -static_assert(std::is_same<__swift_pthread_key_t, pthread_key_t>::value, |
| 130 | +static_assert(std::is_same<__swift_thread_key_t, pthread_key_t>::value, |
104 | 131 | "This platform's pthread_key_t differs. If you hit this assert, "
|
105 | 132 | "fix __swift_pthread_key_t's typedef in LibcShims.h by adding an "
|
106 | 133 | "#if guard and definition for your platform");
|
107 | 134 |
|
108 | 135 | SWIFT_RUNTIME_STDLIB_INTERFACE
|
109 |
| -int swift::_swift_stdlib_pthread_key_create( |
110 |
| - __swift_pthread_key_t * _Nonnull key, |
111 |
| - void (* _Nullable destructor)(void *) |
112 |
| -) { |
| 136 | +int |
| 137 | +swift::_swift_stdlib_thread_key_create(__swift_thread_key_t * _Nonnull key, |
| 138 | + void (* _Nullable destructor)(void *)) { |
113 | 139 | return pthread_key_create(key, destructor);
|
114 | 140 | }
|
115 | 141 |
|
116 | 142 | SWIFT_RUNTIME_STDLIB_INTERFACE
|
117 |
| -void * _Nullable swift::_swift_stdlib_pthread_getspecific( |
118 |
| - __swift_pthread_key_t key |
119 |
| -) { |
| 143 | +void * _Nullable |
| 144 | +swift::_swift_stdlib_thread_getspecific(__swift_thread_key_t key) { |
120 | 145 | return pthread_getspecific(key);
|
121 | 146 | }
|
122 | 147 |
|
123 | 148 | SWIFT_RUNTIME_STDLIB_INTERFACE
|
124 |
| -int swift::_swift_stdlib_pthread_setspecific( |
125 |
| - __swift_pthread_key_t key, const void * _Nullable value |
126 |
| -) { |
| 149 | +int swift::_swift_stdlib_thread_setspecific(__swift_thread_key_t key, |
| 150 | + const void * _Nullable value) { |
127 | 151 | return pthread_setspecific(key, value);
|
128 | 152 | }
|
| 153 | +#endif |
129 | 154 |
|
130 | 155 | #if defined(__APPLE__)
|
131 | 156 | #include <malloc/malloc.h>
|
|
0 commit comments