[Threading] Don't use TLS keys as template arguments.

There's no guarantee that e.g. pthread_key_t is an integral type.  It could
be some kind of struct, or some other thing that isn't valid as a template
argument.

rdar://90776105
This commit is contained in:
Alastair Houghton
2022-05-04 11:08:09 +01:00
parent c7c1c1be80
commit eb4c81d60e
13 changed files with 122 additions and 70 deletions

View File

@@ -149,16 +149,16 @@ inline void once_impl(once_t &predicate, void (*fn)(void *), void *context) {
#define SWIFT_THREAD_LOCAL thread_local
#endif
using tls_key = pthread_key_t;
using tls_dtor = void (*)(void *);
using tls_key_t = pthread_key_t;
using tls_dtor_t = void (*)(void *);
inline bool tls_alloc(tls_key &key, tls_dtor dtor) {
inline bool tls_alloc(tls_key_t &key, tls_dtor_t dtor) {
return pthread_key_create(&key, dtor) == 0;
}
inline void *tls_get(tls_key key) { return pthread_getspecific(key); }
inline void *tls_get(tls_key_t key) { return pthread_getspecific(key); }
inline void tls_set(tls_key key, void *value) {
inline void tls_set(tls_key_t key, void *value) {
pthread_setspecific(key, value);
}