@@ -99,37 +99,60 @@ pub struct LocalKey<T> {
99
99
100
100
/// Declare a new thread local storage key of type `std::thread::LocalKey`.
101
101
///
102
- /// See [LocalKey documentation](thread/struct.LocalKey.html) for more information.
102
+ /// See [LocalKey documentation](thread/struct.LocalKey.html) for more
103
+ /// information.
103
104
#[ macro_export]
104
105
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
105
106
#[ allow_internal_unstable]
107
+ #[ cfg( not( no_elf_tls) ) ]
106
108
macro_rules! thread_local {
107
109
( static $name: ident: $t: ty = $init: expr) => (
108
- static $name: :: std:: thread:: LocalKey <$t> = {
109
- #[ cfg_attr( all( any( target_os = "macos" , target_os = "linux" ) ,
110
- not( target_arch = "aarch64" ) ) ,
111
- thread_local) ]
112
- static __KEY: :: std:: thread:: __LocalKeyInner<$t> =
113
- :: std:: thread:: __LocalKeyInner:: new( ) ;
114
- fn __init( ) -> $t { $init }
115
- fn __getit( ) -> & ' static :: std:: thread:: __LocalKeyInner<$t> { & __KEY }
116
- :: std:: thread:: LocalKey :: new( __getit, __init)
117
- } ;
110
+ static $name: :: std:: thread:: LocalKey <$t> =
111
+ __thread_local_inner!( $t, $init,
112
+ #[ cfg_attr( all( any( target_os = "macos" , target_os = "linux" ) ,
113
+ not( target_arch = "aarch64" ) ) ,
114
+ thread_local) ] ) ;
118
115
) ;
119
116
( pub static $name: ident: $t: ty = $init: expr) => (
120
- pub static $name: :: std:: thread:: LocalKey <$t> = {
121
- #[ cfg_attr( all( any( target_os = "macos" , target_os = "linux" ) ,
122
- not( target_arch = "aarch64" ) ) ,
123
- thread_local) ]
124
- static __KEY: :: std:: thread:: __LocalKeyInner<$t> =
125
- :: std:: thread:: __LocalKeyInner:: new( ) ;
126
- fn __init( ) -> $t { $init }
127
- fn __getit( ) -> & ' static :: std:: thread:: __LocalKeyInner<$t> { & __KEY }
128
- :: std:: thread:: LocalKey :: new( __getit, __init)
129
- } ;
117
+ pub static $name: :: std:: thread:: LocalKey <$t> =
118
+ __thread_local_inner!( $t, $init,
119
+ #[ cfg_attr( all( any( target_os = "macos" , target_os = "linux" ) ,
120
+ not( target_arch = "aarch64" ) ) ,
121
+ thread_local) ] ) ;
130
122
) ;
131
123
}
132
124
125
+ #[ macro_export]
126
+ #[ stable( feature = "rust1" , since = "1.0.0" ) ]
127
+ #[ allow_internal_unstable]
128
+ #[ cfg( no_elf_tls) ]
129
+ macro_rules! thread_local {
130
+ ( static $name: ident: $t: ty = $init: expr) => (
131
+ static $name: :: std:: thread:: LocalKey <$t> =
132
+ __thread_local_inner!( $t, $init, #[ ] ) ;
133
+ ) ;
134
+ ( pub static $name: ident: $t: ty = $init: expr) => (
135
+ pub static $name: :: std:: thread:: LocalKey <$t> =
136
+ __thread_local_inner!( $t, $init, #[ ] ) ;
137
+ ) ;
138
+ }
139
+
140
+ #[ doc( hidden) ]
141
+ #[ unstable( feature = "thread_local_internals" ,
142
+ reason = "should not be necessary" ) ]
143
+ #[ macro_export]
144
+ #[ allow_internal_unstable]
145
+ macro_rules! __thread_local_inner {
146
+ ( $t: ty, $init: expr, #[ $( $attr: meta) ,* ] ) => { {
147
+ $( #[ $attr] ) *
148
+ static __KEY: :: std:: thread:: __LocalKeyInner<$t> =
149
+ :: std:: thread:: __LocalKeyInner:: new( ) ;
150
+ fn __init( ) -> $t { $init }
151
+ fn __getit( ) -> & ' static :: std:: thread:: __LocalKeyInner<$t> { & __KEY }
152
+ :: std:: thread:: LocalKey :: new( __getit, __init)
153
+ } }
154
+ }
155
+
133
156
/// Indicator of the state of a thread local storage key.
134
157
#[ unstable( feature = "std_misc" ,
135
158
reason = "state querying was recently added" ) ]
@@ -163,7 +186,10 @@ pub enum LocalKeyState {
163
186
164
187
impl < T : ' static > LocalKey < T > {
165
188
#[ doc( hidden) ]
166
- pub const fn new ( inner : fn ( ) -> & ' static __KeyInner < T > , init : fn ( ) -> T ) -> LocalKey < T > {
189
+ #[ unstable( feature = "thread_local_internals" ,
190
+ reason = "recently added to create a key" ) ]
191
+ pub const fn new ( inner : fn ( ) -> & ' static __KeyInner < T > ,
192
+ init : fn ( ) -> T ) -> LocalKey < T > {
167
193
LocalKey {
168
194
inner : inner,
169
195
init : init
@@ -240,7 +266,9 @@ impl<T: 'static> LocalKey<T> {
240
266
}
241
267
}
242
268
243
- #[ cfg( all( any( target_os = "macos" , target_os = "linux" ) , not( target_arch = "aarch64" ) ) ) ]
269
+ #[ cfg( all( any( target_os = "macos" , target_os = "linux" ) ,
270
+ not( target_arch = "aarch64" ) ,
271
+ not( no_elf_tls) ) ) ]
244
272
#[ doc( hidden) ]
245
273
mod imp {
246
274
use prelude:: v1:: * ;
@@ -371,7 +399,9 @@ mod imp {
371
399
}
372
400
}
373
401
374
- #[ cfg( any( not( any( target_os = "macos" , target_os = "linux" ) ) , target_arch = "aarch64" ) ) ]
402
+ #[ cfg( any( not( any( target_os = "macos" , target_os = "linux" ) ) ,
403
+ target_arch = "aarch64" ,
404
+ no_elf_tls) ) ]
375
405
#[ doc( hidden) ]
376
406
mod imp {
377
407
use prelude:: v1:: * ;
0 commit comments