@@ -4,46 +4,73 @@ use super::thread::Thread;
44use crate :: mem:: ManuallyDrop ;
55use crate :: ptr;
66use crate :: sys:: thread as imp;
7- use crate :: sys:: thread_local:: local_pointer;
87
98const NONE : * mut ( ) = ptr:: null_mut ( ) ;
109const BUSY : * mut ( ) = ptr:: without_provenance_mut ( 1 ) ;
1110const DESTROYED : * mut ( ) = ptr:: without_provenance_mut ( 2 ) ;
1211
13- local_pointer ! {
14- static CURRENT ;
12+ cfg_select ! {
13+ test => {
14+ use realstd:: test_internals:: CURRENT_THREAD as CURRENT ;
15+ }
16+ _ => {
17+ use crate :: sys:: thread_local:: local_pointer;
18+
19+ local_pointer! {
20+ pub static CURRENT ;
21+ }
22+ }
1523}
1624
1725/// Persistent storage for the thread ID.
1826///
1927/// We store the thread ID so that it never gets destroyed during the lifetime
2028/// of a thread, either using `#[thread_local]` or multiple `local_pointer!`s.
21- pub ( super ) mod id {
29+ pub mod id {
2230 use super :: * ;
2331
2432 cfg_select ! {
2533 target_thread_local => {
26- use crate :: cell:: Cell ;
34+ cfg_select! {
35+ test => {
36+ use realstd:: test_internals:: CURRENT_THREAD_ID as ID ;
37+ }
38+ _ => {
39+ use crate :: cell:: Cell ;
2740
28- #[ thread_local]
29- static ID : Cell <Option <ThreadId >> = Cell :: new( None ) ;
41+ #[ thread_local]
42+ pub static ID : Cell <Option <u64 >> = Cell :: new( None ) ;
3043
44+ }
45+ }
3146 pub ( super ) const CHEAP : bool = true ;
3247
3348 pub ( crate ) fn get( ) -> Option <ThreadId > {
34- ID . get( )
49+ ID . get( ) . and_then ( ThreadId :: from_u64 )
3550 }
3651
3752 pub ( super ) fn set( id: ThreadId ) {
38- ID . set( Some ( id) )
53+ ID . set( Some ( id. as_u64 ( ) . get ( ) ) )
3954 }
4055 }
4156 target_pointer_width = "16" => {
42- local_pointer! {
43- static ID0 ;
44- static ID16 ;
45- static ID32 ;
46- static ID48 ;
57+ cfg_select! {
58+ test => {
59+ use realstd:: test_internals:: CURRENT_THREAD_ID0 as ID0 ;
60+ use realstd:: test_internals:: CURRENT_THREAD_ID16 as ID16 ;
61+ use realstd:: test_internals:: CURRENT_THREAD_ID32 as ID32 ;
62+ use realstd:: test_internals:: CURRENT_THREAD_ID48 as ID48 ;
63+ }
64+ _ => {
65+ use crate :: sys:: thread_local:: local_pointer;
66+
67+ local_pointer! {
68+ pub static ID0 ;
69+ pub static ID16 ;
70+ pub static ID32 ;
71+ pub static ID48 ;
72+ }
73+ }
4774 }
4875
4976 pub ( super ) const CHEAP : bool = false ;
@@ -65,9 +92,19 @@ pub(super) mod id {
6592 }
6693 }
6794 target_pointer_width = "32" => {
68- local_pointer! {
69- static ID0 ;
70- static ID32 ;
95+ cfg_select! {
96+ test => {
97+ use realstd:: test_internals:: CURRENT_THREAD_ID0 as ID0 ;
98+ use realstd:: test_internals:: CURRENT_THREAD_ID32 as ID32 ;
99+ }
100+ _ => {
101+ use crate :: sys:: thread_local:: local_pointer;
102+
103+ local_pointer! {
104+ pub static ID0 ;
105+ pub static ID32 ;
106+ }
107+ }
71108 }
72109
73110 pub ( super ) const CHEAP : bool = false ;
@@ -85,8 +122,17 @@ pub(super) mod id {
85122 }
86123 }
87124 _ => {
88- local_pointer! {
89- static ID ;
125+ cfg_select! {
126+ test => {
127+ use realstd:: test_internals:: CURRENT_THREAD_ID as ID ;
128+ }
129+ _ => {
130+ use crate :: sys:: thread_local:: local_pointer;
131+
132+ local_pointer! {
133+ pub static ID ;
134+ }
135+ }
90136 }
91137
92138 pub ( super ) const CHEAP : bool = true ;
0 commit comments