Skip to content

Commit 82dbb9e

Browse files
authored
Unrolled build for rust-lang#123505
Rollup merge of rust-lang#123505 - ChrisDenton:revert-121666, r=workingjubilee Revert "Use OS thread name by default" This reverts rust-lang#121666 (Use the OS thread name by default if `THREAD_INFO` has not been initialized) due to rust-lang#123495 (Thread names are not always valid UTF-8). It's not a direct revert because there have been other changes since that PR.
2 parents 9d79cd5 + 7d00826 commit 82dbb9e

File tree

13 files changed

+10
-164
lines changed

13 files changed

+10
-164
lines changed

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

+1-5
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
use super::abi;
44
use super::thread_local_dtor::run_dtors;
5-
use crate::ffi::{CStr, CString};
5+
use crate::ffi::CStr;
66
use crate::io;
77
use crate::mem;
88
use crate::num::NonZero;
@@ -71,10 +71,6 @@ impl Thread {
7171
// nope
7272
}
7373

74-
pub fn get_name() -> Option<CString> {
75-
None
76-
}
77-
7874
#[inline]
7975
pub fn sleep(dur: Duration) {
8076
unsafe {

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

+1-5
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use super::{
88
};
99
use crate::{
1010
cell::UnsafeCell,
11-
ffi::{CStr, CString},
11+
ffi::CStr,
1212
hint, io,
1313
mem::ManuallyDrop,
1414
num::NonZero,
@@ -204,10 +204,6 @@ impl Thread {
204204
// nope
205205
}
206206

207-
pub fn get_name() -> Option<CString> {
208-
None
209-
}
210-
211207
pub fn sleep(dur: Duration) {
212208
for timeout in dur2reltims(dur) {
213209
expect_success(unsafe { abi::dly_tsk(timeout) }, &"dly_tsk");

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

+1-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#![cfg_attr(test, allow(dead_code))] // why is this necessary?
22
use super::unsupported;
3-
use crate::ffi::{CStr, CString};
3+
use crate::ffi::CStr;
44
use crate::io;
55
use crate::num::NonZero;
66
use crate::time::Duration;
@@ -133,10 +133,6 @@ impl Thread {
133133
// which succeeds as-is with the SGX target.
134134
}
135135

136-
pub fn get_name() -> Option<CString> {
137-
None
138-
}
139-
140136
pub fn sleep(dur: Duration) {
141137
usercalls::wait_timeout(0, dur, || true);
142138
}

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

+1-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use core::convert::TryInto;
22

33
use crate::cmp;
4-
use crate::ffi::{CStr, CString};
4+
use crate::ffi::CStr;
55
use crate::io;
66
use crate::mem;
77
use crate::num::NonZero;
@@ -101,10 +101,6 @@ impl Thread {
101101
// contact the teeos rustzone team.
102102
}
103103

104-
pub fn get_name() -> Option<CString> {
105-
None
106-
}
107-
108104
/// only main thread could wait for sometime in teeos
109105
pub fn sleep(dur: Duration) {
110106
let sleep_millis = dur.as_millis();

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

+1-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use super::unsupported;
2-
use crate::ffi::{CStr, CString};
2+
use crate::ffi::CStr;
33
use crate::io;
44
use crate::num::NonZero;
55
use crate::ptr::NonNull;
@@ -23,10 +23,6 @@ impl Thread {
2323
// nope
2424
}
2525

26-
pub fn get_name() -> Option<CString> {
27-
None
28-
}
29-
3026
pub fn sleep(dur: Duration) {
3127
let boot_services: NonNull<r_efi::efi::BootServices> =
3228
crate::os::uefi::env::boot_services().expect("can't sleep").cast();

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

+1-73
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::cmp;
2-
use crate::ffi::{CStr, CString};
2+
use crate::ffi::CStr;
33
use crate::io;
44
use crate::mem;
55
use crate::num::NonZero;
@@ -228,78 +228,6 @@ impl Thread {
228228
// Newlib, Emscripten, and VxWorks have no way to set a thread name.
229229
}
230230

231-
#[cfg(any(
232-
target_os = "linux",
233-
target_os = "freebsd",
234-
target_os = "netbsd",
235-
target_os = "solaris",
236-
target_os = "illumos"
237-
))]
238-
pub fn get_name() -> Option<CString> {
239-
#[cfg(target_os = "linux")]
240-
const TASK_COMM_LEN: usize = 16;
241-
#[cfg(target_os = "freebsd")]
242-
const TASK_COMM_LEN: usize = libc::MAXCOMLEN + 1;
243-
#[cfg(any(target_os = "netbsd", target_os = "solaris", target_os = "illumos"))]
244-
const TASK_COMM_LEN: usize = 32;
245-
let mut name = vec![0u8; TASK_COMM_LEN];
246-
let res = unsafe {
247-
libc::pthread_getname_np(libc::pthread_self(), name.as_mut_ptr().cast(), name.len())
248-
};
249-
if res != 0 {
250-
return None;
251-
}
252-
name.truncate(name.iter().position(|&c| c == 0)?);
253-
CString::new(name).ok()
254-
}
255-
256-
#[cfg(any(target_os = "macos", target_os = "ios", target_os = "tvos", target_os = "watchos"))]
257-
pub fn get_name() -> Option<CString> {
258-
let mut name = vec![0u8; libc::MAXTHREADNAMESIZE];
259-
let res = unsafe {
260-
libc::pthread_getname_np(libc::pthread_self(), name.as_mut_ptr().cast(), name.len())
261-
};
262-
if res != 0 {
263-
return None;
264-
}
265-
name.truncate(name.iter().position(|&c| c == 0)?);
266-
CString::new(name).ok()
267-
}
268-
269-
#[cfg(target_os = "haiku")]
270-
pub fn get_name() -> Option<CString> {
271-
unsafe {
272-
let mut tinfo = mem::MaybeUninit::<libc::thread_info>::uninit();
273-
// See BeOS teams group and threads api.
274-
// https://www.haiku-os.org/legacy-docs/bebook/TheKernelKit_ThreadsAndTeams_Overview.html
275-
let thread_self = libc::find_thread(ptr::null_mut());
276-
let res = libc::get_thread_info(thread_self, tinfo.as_mut_ptr());
277-
if res != libc::B_OK {
278-
return None;
279-
}
280-
let info = tinfo.assume_init();
281-
let name =
282-
core::slice::from_raw_parts(info.name.as_ptr() as *const u8, info.name.len());
283-
CStr::from_bytes_until_nul(name).map(CStr::to_owned).ok()
284-
}
285-
}
286-
287-
#[cfg(not(any(
288-
target_os = "linux",
289-
target_os = "freebsd",
290-
target_os = "netbsd",
291-
target_os = "macos",
292-
target_os = "ios",
293-
target_os = "tvos",
294-
target_os = "watchos",
295-
target_os = "haiku",
296-
target_os = "solaris",
297-
target_os = "illumos"
298-
)))]
299-
pub fn get_name() -> Option<CString> {
300-
None
301-
}
302-
303231
#[cfg(not(target_os = "espidf"))]
304232
pub fn sleep(dur: Duration) {
305233
let mut secs = dur.as_secs();

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

+1-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use super::unsupported;
2-
use crate::ffi::{CStr, CString};
2+
use crate::ffi::CStr;
33
use crate::io;
44
use crate::num::NonZero;
55
use crate::time::Duration;
@@ -22,10 +22,6 @@ impl Thread {
2222
// nope
2323
}
2424

25-
pub fn get_name() -> Option<CString> {
26-
None
27-
}
28-
2925
pub fn sleep(_dur: Duration) {
3026
panic!("can't sleep");
3127
}

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

+1-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::ffi::{CStr, CString};
1+
use crate::ffi::CStr;
22
use crate::io;
33
use crate::mem;
44
use crate::num::NonZero;
@@ -134,10 +134,6 @@ impl Thread {
134134
// nope
135135
}
136136

137-
pub fn get_name() -> Option<CString> {
138-
None
139-
}
140-
141137
pub fn sleep(dur: Duration) {
142138
let nanos = dur.as_nanos();
143139
assert!(nanos <= u64::MAX as u128);

library/std/src/sys/pal/wasm/atomics/thread.rs

-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use crate::ffi::CStr;
2-
use crate::ffi::CString;
32
use crate::io;
43
use crate::num::NonZero;
54
use crate::sys::unsupported;
@@ -18,9 +17,6 @@ impl Thread {
1817
pub fn yield_now() {}
1918

2019
pub fn set_name(_name: &CStr) {}
21-
pub fn get_name() -> Option<CString> {
22-
None
23-
}
2420

2521
pub fn sleep(dur: Duration) {
2622
use crate::arch::wasm32;

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

-24
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ use crate::sys::handle::Handle;
99
use crate::sys::stack_overflow;
1010
use crate::sys_common::FromInner;
1111
use crate::time::Duration;
12-
use alloc::ffi::CString;
1312
use core::ffi::c_void;
1413

1514
use super::time::WaitableTimer;
@@ -67,29 +66,6 @@ impl Thread {
6766
};
6867
}
6968

70-
pub fn get_name() -> Option<CString> {
71-
unsafe {
72-
let mut ptr = core::ptr::null_mut();
73-
let result = c::GetThreadDescription(c::GetCurrentThread(), &mut ptr);
74-
if result < 0 {
75-
return None;
76-
}
77-
let name = String::from_utf16_lossy({
78-
let mut len = 0;
79-
while *ptr.add(len) != 0 {
80-
len += 1;
81-
}
82-
core::slice::from_raw_parts(ptr, len)
83-
})
84-
.into_bytes();
85-
// Attempt to free the memory.
86-
// This should never fail but if it does then there's not much we can do about it.
87-
let result = c::LocalFree(ptr.cast::<c_void>());
88-
debug_assert!(result.is_null());
89-
if name.is_empty() { None } else { Some(CString::from_vec_unchecked(name)) }
90-
}
91-
}
92-
9369
pub fn join(self) {
9470
let rc = unsafe { c::WaitForSingleObject(self.handle.as_raw_handle(), c::INFINITE) };
9571
if rc == c::WAIT_FAILED {

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

+1-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::ffi::{CStr, CString};
1+
use crate::ffi::CStr;
22
use crate::io;
33
use crate::num::NonZero;
44
use crate::os::xous::ffi::{
@@ -113,10 +113,6 @@ impl Thread {
113113
// nope
114114
}
115115

116-
pub fn get_name() -> Option<CString> {
117-
None
118-
}
119-
120116
pub fn sleep(dur: Duration) {
121117
// Because the sleep server works on units of `usized milliseconds`, split
122118
// the messages up into these chunks. This means we may run into issues

library/std/src/thread/mod.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -694,9 +694,7 @@ pub(crate) fn set_current(thread: Thread) {
694694
/// In contrast to the public `current` function, this will not panic if called
695695
/// from inside a TLS destructor.
696696
pub(crate) fn try_current() -> Option<Thread> {
697-
CURRENT
698-
.try_with(|current| current.get_or_init(|| Thread::new(imp::Thread::get_name())).clone())
699-
.ok()
697+
CURRENT.try_with(|current| current.get_or_init(|| Thread::new(None)).clone()).ok()
700698
}
701699

702700
/// Gets a handle to the thread that invokes it.

library/std/src/thread/tests.rs

-20
Original file line numberDiff line numberDiff line change
@@ -69,26 +69,6 @@ fn test_named_thread_truncation() {
6969
result.unwrap().join().unwrap();
7070
}
7171

72-
#[cfg(any(
73-
all(target_os = "windows", not(target_vendor = "win7")),
74-
target_os = "linux",
75-
target_os = "macos",
76-
target_os = "ios",
77-
target_os = "tvos",
78-
target_os = "watchos"
79-
))]
80-
#[test]
81-
fn test_get_os_named_thread() {
82-
use crate::sys::thread::Thread;
83-
// Spawn a new thread to avoid interfering with other tests running on this thread.
84-
let handler = thread::spawn(|| {
85-
let name = c"test me please";
86-
Thread::set_name(name);
87-
assert_eq!(name, Thread::get_name().unwrap().as_c_str());
88-
});
89-
handler.join().unwrap();
90-
}
91-
9272
#[test]
9373
#[should_panic]
9474
fn test_invalid_named_thread() {

0 commit comments

Comments
 (0)