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 {
34
34
LazyKey { key : AtomicUsize :: new ( KEY_SENTVAL ) , dtor }
35
35
}
36
36
37
- #[ inline]
37
+ #[ inline( always ) ]
38
38
pub fn force ( & self ) -> super :: Key {
39
39
match self . key . load ( Ordering :: Acquire ) {
40
40
KEY_SENTVAL => self . lazy_init ( ) as super :: Key ,
41
41
n => n as super :: Key ,
42
42
}
43
43
}
44
44
45
+ #[ cold]
46
+ #[ inline( never) ]
45
47
fn lazy_init ( & self ) -> usize {
46
48
// POSIX allows the key created here to be KEY_SENTVAL, but the compare_exchange
47
49
// 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 {
58
58
}
59
59
}
60
60
61
- #[ inline]
61
+ #[ inline( always ) ]
62
62
pub fn force ( & ' static self ) -> Key {
63
63
match self . key . load ( Acquire ) {
64
64
0 => unsafe { self . init ( ) } ,
@@ -67,6 +67,7 @@ impl LazyKey {
67
67
}
68
68
69
69
#[ cold]
70
+ #[ inline( never) ]
70
71
unsafe fn init ( & ' static self ) -> Key {
71
72
if self . dtor . is_some ( ) {
72
73
let mut pending = c:: FALSE ;
Original file line number Diff line number Diff line change @@ -67,6 +67,7 @@ unsafe extern "Rust" {
67
67
static DTORS : Atomic < * mut Node > ;
68
68
}
69
69
70
+ #[ inline]
70
71
fn tls_ptr_addr ( ) -> * mut * mut u8 {
71
72
let mut tp: usize ;
72
73
unsafe {
@@ -80,14 +81,20 @@ fn tls_ptr_addr() -> *mut *mut u8 {
80
81
81
82
/// Creates an area of memory that's unique per thread. This area will
82
83
/// contain all thread local pointers.
84
+ #[ inline]
83
85
fn tls_table ( ) -> & ' static mut [ * mut u8 ] {
84
86
let tp = tls_ptr_addr ( ) ;
85
87
86
88
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 ( )
90
92
}
93
+ }
94
+
95
+ #[ cold]
96
+ #[ inline( never) ]
97
+ fn tls_table_slow ( ) -> & ' static mut [ * mut u8 ] {
91
98
// If the TP register is `0`, then this thread hasn't initialized
92
99
// its TLS yet. Allocate a new page to store this memory.
93
100
let tp = unsafe {
Original file line number Diff line number Diff line change @@ -68,6 +68,7 @@ impl<T: 'static> Storage<T> {
68
68
///
69
69
/// The resulting pointer may not be used after reentrant inialialization
70
70
/// or thread destruction has occurred.
71
+ #[ inline]
71
72
pub fn get ( & ' static self , i : Option < & mut Option < T > > , f : impl FnOnce ( ) -> T ) -> * const T {
72
73
let key = self . key . force ( ) ;
73
74
let ptr = unsafe { get ( key) as * mut Value < T > } ;
@@ -84,6 +85,8 @@ impl<T: 'static> Storage<T> {
84
85
/// # Safety
85
86
/// * `key` must be the result of calling `self.key.force()`
86
87
/// * `ptr` must be the current value associated with `key`.
88
+ #[ cold]
89
+ #[ inline( never) ]
87
90
unsafe fn try_initialize (
88
91
key : Key ,
89
92
ptr : * mut Value < T > ,
You can’t perform that action at this time.
0 commit comments