File tree 2 files changed +11
-13
lines changed
library/std/src/sync/mpmc
2 files changed +11
-13
lines changed Original file line number Diff line number Diff line change 1
1
//! Thread-local channel context.
2
2
3
3
use super :: select:: Selected ;
4
+ use super :: waker:: current_thread_id;
4
5
5
6
use crate :: cell:: Cell ;
6
7
use crate :: ptr;
7
8
use crate :: sync:: atomic:: { AtomicPtr , AtomicUsize , Ordering } ;
8
9
use crate :: sync:: Arc ;
9
- use crate :: thread:: { self , Thread , ThreadId } ;
10
+ use crate :: thread:: { self , Thread } ;
10
11
use crate :: time:: Instant ;
11
12
12
13
/// Thread-local context.
@@ -28,7 +29,7 @@ struct Inner {
28
29
thread : Thread ,
29
30
30
31
/// Thread id.
31
- thread_id : ThreadId ,
32
+ thread_id : usize ,
32
33
}
33
34
34
35
impl Context {
@@ -70,7 +71,7 @@ impl Context {
70
71
select : AtomicUsize :: new ( Selected :: Waiting . into ( ) ) ,
71
72
packet : AtomicPtr :: new ( ptr:: null_mut ( ) ) ,
72
73
thread : thread:: current ( ) ,
73
- thread_id : thread :: current ( ) . id ( ) ,
74
+ thread_id : current_thread_id ( ) ,
74
75
} ) ,
75
76
}
76
77
}
@@ -148,7 +149,7 @@ impl Context {
148
149
149
150
/// Returns the id of the thread this context belongs to.
150
151
#[ inline]
151
- pub fn thread_id ( & self ) -> ThreadId {
152
+ pub fn thread_id ( & self ) -> usize {
152
153
self . inner . thread_id
153
154
}
154
155
}
Original file line number Diff line number Diff line change @@ -6,7 +6,6 @@ use super::select::{Operation, Selected};
6
6
use crate :: ptr;
7
7
use crate :: sync:: atomic:: { AtomicBool , Ordering } ;
8
8
use crate :: sync:: Mutex ;
9
- use crate :: thread:: { self , ThreadId } ;
10
9
11
10
/// Represents a thread blocked on a specific channel operation.
12
11
pub ( crate ) struct Entry {
@@ -195,13 +194,11 @@ impl Drop for SyncWaker {
195
194
}
196
195
}
197
196
198
- /// Returns the id of the current thread.
197
+ /// Returns a unique id for the current thread.
199
198
#[ inline]
200
- fn current_thread_id ( ) -> ThreadId {
201
- thread_local ! {
202
- /// Cached thread-local id.
203
- static THREAD_ID : ThreadId = thread:: current( ) . id( ) ;
204
- }
205
-
206
- THREAD_ID . try_with ( |id| * id) . unwrap_or_else ( |_| thread:: current ( ) . id ( ) )
199
+ pub fn current_thread_id ( ) -> usize {
200
+ // `u8` is not drop so this variable will be available during thread destruction,
201
+ // whereas `thread::current()` would not be
202
+ thread_local ! { static DUMMY : u8 = 0 }
203
+ DUMMY . with ( |x| ( x as * const u8 ) . addr ( ) )
207
204
}
You can’t perform that action at this time.
0 commit comments