Skip to content

Commit 7668418

Browse files
committed
std: move thread::current TLS variable out of thread_info
1 parent 5b9d7ab commit 7668418

File tree

16 files changed

+29
-176
lines changed

16 files changed

+29
-176
lines changed

library/std/src/panicking.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ use crate::sync::atomic::{AtomicBool, Ordering};
2121
use crate::sync::{PoisonError, RwLock};
2222
use crate::sys::stdio::panic_output;
2323
use crate::sys_common::backtrace;
24-
use crate::sys_common::thread_info;
2524
use crate::thread;
2625

2726
#[cfg(not(test))]
@@ -256,7 +255,7 @@ fn default_hook(info: &PanicInfo<'_>) {
256255
None => "Box<dyn Any>",
257256
},
258257
};
259-
let thread = thread_info::current_thread();
258+
let thread = thread::try_current();
260259
let name = thread.as_ref().and_then(|t| t.name()).unwrap_or("<unnamed>");
261260

262261
let write = |err: &mut dyn crate::io::Write| {

library/std/src/rt.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@ pub use core::panicking::{panic_display, panic_fmt};
2424

2525
use crate::sync::Once;
2626
use crate::sys;
27-
use crate::sys_common::thread_info;
28-
use crate::thread::Thread;
27+
use crate::thread::{self, Thread};
2928

3029
// Prints to the "panic output", depending on the platform this may be:
3130
// - the standard error output
@@ -96,13 +95,12 @@ unsafe fn init(argc: isize, argv: *const *const u8, sigpipe: u8) {
9695
unsafe {
9796
sys::init(argc, argv, sigpipe);
9897

99-
let main_guard = sys::thread::guard::init();
10098
// Next, set up the current Thread with the guard information we just
10199
// created. Note that this isn't necessary in general for new threads,
102100
// but we just do this to name the main thread and to give it correct
103101
// info about the stack bounds.
104102
let thread = Thread::new(Some(rtunwrap!(Ok, CString::new("main"))));
105-
thread_info::set(main_guard, thread);
103+
thread::set_current(thread);
106104
}
107105
}
108106

library/std/src/sys/pal/hermit/thread.rs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -104,13 +104,3 @@ impl Thread {
104104
pub fn available_parallelism() -> io::Result<NonZero<usize>> {
105105
unsafe { Ok(NonZero::new_unchecked(abi::get_processor_count())) }
106106
}
107-
108-
pub mod guard {
109-
pub type Guard = !;
110-
pub unsafe fn current() -> Option<Guard> {
111-
None
112-
}
113-
pub unsafe fn init() -> Option<Guard> {
114-
None
115-
}
116-
}

library/std/src/sys/pal/itron/thread.rs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -312,16 +312,6 @@ impl Drop for Thread {
312312
}
313313
}
314314

315-
pub mod guard {
316-
pub type Guard = !;
317-
pub unsafe fn current() -> Option<Guard> {
318-
None
319-
}
320-
pub unsafe fn init() -> Option<Guard> {
321-
None
322-
}
323-
}
324-
325315
/// Terminate and delete the specified task.
326316
///
327317
/// This function will abort if `deleted_task` refers to the calling task.

library/std/src/sys/pal/sgx/thread.rs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -149,13 +149,3 @@ impl Thread {
149149
pub fn available_parallelism() -> io::Result<NonZero<usize>> {
150150
unsupported()
151151
}
152-
153-
pub mod guard {
154-
pub type Guard = !;
155-
pub unsafe fn current() -> Option<Guard> {
156-
None
157-
}
158-
pub unsafe fn init() -> Option<Guard> {
159-
None
160-
}
161-
}

library/std/src/sys/pal/teeos/thread.rs

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -151,18 +151,6 @@ pub fn available_parallelism() -> io::Result<NonZero<usize>> {
151151
))
152152
}
153153

154-
// stub
155-
pub mod guard {
156-
use crate::ops::Range;
157-
pub type Guard = Range<usize>;
158-
pub unsafe fn current() -> Option<Guard> {
159-
None
160-
}
161-
pub unsafe fn init() -> Option<Guard> {
162-
None
163-
}
164-
}
165-
166154
fn min_stack_size(_: *const libc::pthread_attr_t) -> usize {
167155
libc::PTHREAD_STACK_MIN.try_into().expect("Infallible")
168156
}

library/std/src/sys/pal/uefi/thread.rs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,3 @@ pub fn available_parallelism() -> io::Result<NonZero<usize>> {
5252
// UEFI is single threaded
5353
Ok(NonZero::new(1).unwrap())
5454
}
55-
56-
pub mod guard {
57-
pub type Guard = !;
58-
pub unsafe fn current() -> Option<Guard> {
59-
None
60-
}
61-
pub unsafe fn init() -> Option<Guard> {
62-
None
63-
}
64-
}

library/std/src/sys/pal/unix/thread.rs

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -729,17 +729,6 @@ mod cgroups {
729729
}
730730
}
731731

732-
pub mod guard {
733-
use crate::ops::Range;
734-
pub type Guard = Range<usize>;
735-
pub unsafe fn current() -> Option<Guard> {
736-
None
737-
}
738-
pub unsafe fn init() -> Option<Guard> {
739-
None
740-
}
741-
}
742-
743732
// glibc >= 2.15 has a __pthread_get_minstack() function that returns
744733
// PTHREAD_STACK_MIN plus bytes needed for thread-local storage.
745734
// We need that information to avoid blowing up when a small stack

library/std/src/sys/pal/unsupported/thread.rs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,3 @@ impl Thread {
3838
pub fn available_parallelism() -> io::Result<NonZero<usize>> {
3939
unsupported()
4040
}
41-
42-
pub mod guard {
43-
pub type Guard = !;
44-
pub unsafe fn current() -> Option<Guard> {
45-
None
46-
}
47-
pub unsafe fn init() -> Option<Guard> {
48-
None
49-
}
50-
}

library/std/src/sys/pal/wasi/thread.rs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -193,13 +193,3 @@ impl Thread {
193193
pub fn available_parallelism() -> io::Result<NonZero<usize>> {
194194
unsupported()
195195
}
196-
197-
pub mod guard {
198-
pub type Guard = !;
199-
pub unsafe fn current() -> Option<Guard> {
200-
None
201-
}
202-
pub unsafe fn init() -> Option<Guard> {
203-
None
204-
}
205-
}

0 commit comments

Comments
 (0)