1- // ===--- ThreadLocalStorage.h - Thread-local storage interface. --*- C++
2- // -*-===//
1+ // ===--- ThreadLocalStorage.h - Thread-local storage interface. -*- C++ -*-===//
32//
43// This source file is part of the Swift.org open source project
54//
1918#include " Errors.h"
2019#include " Impl.h"
2120#include " Once.h"
21+ #include " TLSKeys.h"
2222
2323namespace swift {
2424
2525// -- Low-level TLS functions -------------------------------------------------
2626
2727#if !SWIFT_THREADING_NONE
28- using tls_key = threading_impl::tls_key ;
29- using tls_dtor = threading_impl::tls_dtor ;
28+ using tls_key_t = threading_impl::tls_key_t ;
29+ using tls_dtor_t = threading_impl::tls_dtor_t ;
3030
3131#if SWIFT_THREADING_USE_RESERVED_TLS_KEYS
32+ using threading_impl::tls_get_key;
3233using threading_impl::tls_init;
3334
3435// / tls_init_once() - Initialize TLS, once only
35- inline void tls_init_once (once_t &token, tls_key key, tls_dtor dtor) {
36+ inline void tls_init_once (once_t &token, tls_key_t key, tls_dtor_t dtor) {
3637 const struct tls_init_info {
37- tls_key &k;
38- tls_dtor d;
38+ tls_key_t &k;
39+ tls_dtor_t d;
3940 } info = {key, dtor};
4041 once (
4142 token,
@@ -47,17 +48,21 @@ inline void tls_init_once(once_t &token, tls_key key, tls_dtor dtor) {
4748 },
4849 (void *)&info);
4950}
51+
52+ inline void tls_init_once (once_t &token, tls_key key, tls_dtor_t dtor) {
53+ tls_init_once (token, tls_get_key (key), dtor);
54+ }
5055#endif // SWIFT_THREADING_USE_RESERVED_TLS_KEYS
5156
5257using threading_impl::tls_alloc;
5358using threading_impl::tls_get;
5459using threading_impl::tls_set;
5560
5661// / tls_alloc_once() - Allocate TLS key, once only
57- inline void tls_alloc_once (once_t &token, tls_key &key, tls_dtor dtor) {
62+ inline void tls_alloc_once (once_t &token, tls_key_t &key, tls_dtor_t dtor) {
5863 const struct tls_init_info {
59- tls_key &k;
60- tls_dtor d;
64+ tls_key_t &k;
65+ tls_dtor_t d;
6166 } info = {key, dtor};
6267 once (
6368 token,
@@ -117,28 +122,30 @@ class ThreadLocalKey {
117122 // We rely on the zero-initialization of objects with static storage
118123 // duration.
119124 once_t onceFlag;
120- tls_key key;
125+ tls_key_t key;
121126
122127public:
123- threading_impl::tls_key getKey () {
128+ threading_impl::tls_key_t getKey () {
124129 once (
125130 onceFlag,
126131 [](void *ctx) {
127- tls_key *pkey = reinterpret_cast <tls_key *>(ctx);
132+ tls_key_t *pkey = reinterpret_cast <tls_key_t *>(ctx);
128133 tls_alloc (*pkey, nullptr );
129134 },
130135 &key);
131136 return key;
132137 }
133138};
134139
140+ #if SWIFT_THREADING_USE_RESERVED_TLS_KEYS
135141// A type representing a constant TLS key, for use on platforms
136142// that provide reserved keys.
137143template <tls_key constantKey>
138144class ConstantThreadLocalKey {
139145public:
140- tls_key getKey () { return constantKey; }
146+ tls_key_t getKey () { return tls_get_key ( constantKey) ; }
141147};
148+ #endif
142149
143150template <class T , class Key >
144151class ThreadLocal {
@@ -172,7 +179,7 @@ class ThreadLocal {
172179// /
173180// / For example
174181// /
175- // / static SWIFT_THREAD_LOCAL_TYPE(int, SWIFT_RESERVED_TLS_KEY_9 ) frobble;
182+ // / static SWIFT_THREAD_LOCAL_TYPE(int, SWIFT_RESERVED_TLS_KEY_T_9 ) frobble;
176183// /
177184// / Because of the fallback path, the default-initialization of the
178185// / type must be equivalent to a bitwise zero-initialization, and the
0 commit comments