Rollup merge of #121666 - ChrisDenton:thread-name, r=cuviper

Use the OS thread name by default if `THREAD_INFO` has not been initialized

Currently if `THREAD_INFO` hasn't been initialized then the name will be set to `None`.  This PR changes it to use the OS thread name by default. This mostly affects foreign threads at the moment but we could expand this to make more use of the OS thread name in the future.

Note: I've only implemented `Thread::get_name` for windows, linux and macos (and macos adjacent) targets. The rest just return `None`.
This commit is contained in:
Matthias Krüger
2024-03-02 16:53:14 +01:00
committed by GitHub
15 changed files with 137 additions and 11 deletions

View File

@@ -1,6 +1,7 @@
#![allow(dead_code)] // stack_guard isn't used right now on all platforms
use crate::cell::OnceCell;
use crate::sys;
use crate::sys::thread::guard::Guard;
use crate::thread::Thread;
@@ -23,7 +24,8 @@ impl ThreadInfo {
{
THREAD_INFO
.try_with(move |thread_info| {
let thread = thread_info.thread.get_or_init(|| Thread::new(None));
let thread =
thread_info.thread.get_or_init(|| Thread::new(sys::thread::Thread::get_name()));
f(thread, &thread_info.stack_guard)
})
.ok()