File tree Expand file tree Collapse file tree 4 files changed +18
-5
lines changed
library/std/src/sys/thread_local Expand file tree Collapse file tree 4 files changed +18
-5
lines changed Original file line number Diff line number Diff line change @@ -34,14 +34,16 @@ impl LazyKey {
3434 LazyKey { key : AtomicUsize :: new ( KEY_SENTVAL ) , dtor }
3535 }
3636
37- #[ inline]
37+ #[ inline( always ) ]
3838 pub fn force ( & self ) -> super :: Key {
3939 match self . key . load ( Ordering :: Acquire ) {
4040 KEY_SENTVAL => self . lazy_init ( ) as super :: Key ,
4141 n => n as super :: Key ,
4242 }
4343 }
4444
45+ #[ cold]
46+ #[ inline( never) ]
4547 fn lazy_init ( & self ) -> usize {
4648 // POSIX allows the key created here to be KEY_SENTVAL, but the compare_exchange
4749 // below relies on using KEY_SENTVAL as a sentinel value to check who won the
Original file line number Diff line number Diff line change @@ -58,7 +58,7 @@ impl LazyKey {
5858 }
5959 }
6060
61- #[ inline]
61+ #[ inline( always ) ]
6262 pub fn force ( & ' static self ) -> Key {
6363 match self . key . load ( Acquire ) {
6464 0 => unsafe { self . init ( ) } ,
@@ -67,6 +67,7 @@ impl LazyKey {
6767 }
6868
6969 #[ cold]
70+ #[ inline( never) ]
7071 unsafe fn init ( & ' static self ) -> Key {
7172 if self . dtor . is_some ( ) {
7273 let mut pending = c:: FALSE ;
Original file line number Diff line number Diff line change @@ -67,6 +67,7 @@ unsafe extern "Rust" {
6767 static DTORS : Atomic < * mut Node > ;
6868}
6969
70+ #[ inline]
7071fn tls_ptr_addr ( ) -> * mut * mut u8 {
7172 let mut tp: usize ;
7273 unsafe {
@@ -80,14 +81,20 @@ fn tls_ptr_addr() -> *mut *mut u8 {
8081
8182/// Creates an area of memory that's unique per thread. This area will
8283/// contain all thread local pointers.
84+ #[ inline]
8385fn tls_table ( ) -> & ' static mut [ * mut u8 ] {
8486 let tp = tls_ptr_addr ( ) ;
8587
8688 if !tp. is_null ( ) {
87- return unsafe {
88- core :: slice :: from_raw_parts_mut ( tp , TLS_MEMORY_SIZE / size_of :: < * mut u8 > ( ) )
89- } ;
89+ unsafe { core :: slice :: from_raw_parts_mut ( tp , TLS_MEMORY_SIZE / size_of :: < * mut u8 > ( ) ) }
90+ } else {
91+ tls_table_slow ( )
9092 }
93+ }
94+
95+ #[ cold]
96+ #[ inline( never) ]
97+ fn tls_table_slow ( ) -> & ' static mut [ * mut u8 ] {
9198 // If the TP register is `0`, then this thread hasn't initialized
9299 // its TLS yet. Allocate a new page to store this memory.
93100 let tp = unsafe {
Original file line number Diff line number Diff line change @@ -68,6 +68,7 @@ impl<T: 'static> Storage<T> {
6868 ///
6969 /// The resulting pointer may not be used after reentrant inialialization
7070 /// or thread destruction has occurred.
71+ #[ inline]
7172 pub fn get ( & ' static self , i : Option < & mut Option < T > > , f : impl FnOnce ( ) -> T ) -> * const T {
7273 let key = self . key . force ( ) ;
7374 let ptr = unsafe { get ( key) as * mut Value < T > } ;
@@ -84,6 +85,8 @@ impl<T: 'static> Storage<T> {
8485 /// # Safety
8586 /// * `key` must be the result of calling `self.key.force()`
8687 /// * `ptr` must be the current value associated with `key`.
88+ #[ cold]
89+ #[ inline( never) ]
8790 unsafe fn try_initialize (
8891 key : Key ,
8992 ptr : * mut Value < T > ,
You can’t perform that action at this time.
0 commit comments