Skip to content

Commit 75741a9

Browse files
committed
[stdlib stubs] Fix up Linux build to know about pthread types.
Adds in Linux platform support for our pthread TLS. Replace usage of PTHREAD_KEYS_MAX with a sentinel value, as it's tricky to define cross-platform and was only lightly used inside sanity checks.
1 parent 6903dd3 commit 75741a9

File tree

3 files changed

+5
-11
lines changed

3 files changed

+5
-11
lines changed

Diff for: stdlib/public/SwiftShims/LibcShims.h

-4
Original file line numberDiff line numberDiff line change
@@ -133,10 +133,6 @@ int _swift_stdlib_pthread_setspecific(
133133
__swift_pthread_key_t key, const void * _Nullable value
134134
);
135135

136-
SWIFT_RUNTIME_STDLIB_INTERFACE
137-
__swift_pthread_key_t _swift_stdlib_PTHREAD_KEYS_MAX(void);
138-
139-
140136
// TODO: Remove horrible workaround when importer does Float80 <-> long double.
141137
#if (defined __i386__ || defined __x86_64__) && !defined _MSC_VER
142138
static inline SWIFT_ALWAYS_INLINE

Diff for: stdlib/public/core/ThreadLocalStorage.swift

+3-2
Original file line numberDiff line numberDiff line change
@@ -117,10 +117,11 @@ internal func _destroyTLS(_ ptr: UnsafeMutableRawPointer?) {
117117

118118
// Lazily created global key for use with pthread TLS
119119
internal let _tlsKey: __swift_pthread_key_t = {
120-
var key: __swift_pthread_key_t = _swift_stdlib_PTHREAD_KEYS_MAX()
120+
let sentinelValue = __swift_pthread_key_t.max
121+
var key: __swift_pthread_key_t = sentinelValue
121122
let success = _swift_stdlib_pthread_key_create(&key, _destroyTLS)
122123
_sanityCheck(success == 0, "somehow failed to create TLS key")
123-
_sanityCheck(key != _swift_stdlib_PTHREAD_KEYS_MAX(), "Didn't make a new key")
124+
_sanityCheck(key != sentinelValue, "Didn't make a new key")
124125
return key
125126
}()
126127

Diff for: stdlib/public/stubs/LibcShims.cpp

+2-5
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
#else
1919
#include <unistd.h>
2020
#endif
21+
#include <pthread.h>
22+
2123
#include <stdlib.h>
2224
#include <stdio.h>
2325
#include <string.h>
@@ -125,11 +127,6 @@ int swift::_swift_stdlib_pthread_setspecific(
125127
return pthread_setspecific(key, value);
126128
}
127129

128-
SWIFT_RUNTIME_STDLIB_INTERFACE
129-
__swift_pthread_key_t _swift_stdlib_PTHREAD_KEYS_MAX(void) {
130-
return PTHREAD_KEYS_MAX;
131-
}
132-
133130
#if defined(__APPLE__)
134131
#include <malloc/malloc.h>
135132
SWIFT_RUNTIME_STDLIB_INTERFACE

0 commit comments

Comments
 (0)