Skip to content

Commit

Permalink
Auto merge of rust-lang#123233 - devnexen:thread_get_name_bsd, r=joboet
Browse files Browse the repository at this point in the history
std::thread: adding freebsd/netbsd to the linux's get_name implementa…

…tion.
  • Loading branch information
bors committed Mar 31, 2024
2 parents 5baf1e1 + c749483 commit 5f358a8
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion library/std/src/sys/pal/unix/thread.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,9 +225,14 @@ impl Thread {
// Newlib, Emscripten, and VxWorks have no way to set a thread name.
}

#[cfg(target_os = "linux")]
#[cfg(any(target_os = "linux", target_os = "freebsd", target_os = "netbsd",))]
pub fn get_name() -> Option<CString> {
#[cfg(target_os = "linux")]
const TASK_COMM_LEN: usize = 16;
#[cfg(target_os = "freebsd")]
const TASK_COMM_LEN: usize = libc::MAXCOMLEN + 1;
#[cfg(target_os = "netbsd")]
const TASK_COMM_LEN: usize = 32;
let mut name = vec![0u8; TASK_COMM_LEN];
let res = unsafe {
libc::pthread_getname_np(libc::pthread_self(), name.as_mut_ptr().cast(), name.len())
Expand All @@ -254,6 +259,8 @@ impl Thread {

#[cfg(not(any(
target_os = "linux",
target_os = "freebsd",
target_os = "netbsd",
target_os = "macos",
target_os = "ios",
target_os = "tvos",
Expand Down

0 comments on commit 5f358a8

Please sign in to comment.