Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

linux: Use pthread_setname_np instead of prctl #100287

Merged
merged 1 commit into from
Aug 11, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions library/std/src/sys/unix/thread.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,9 @@ impl Thread {
debug_assert_eq!(ret, 0);
}

#[cfg(any(target_os = "linux", target_os = "android"))]
#[cfg(target_os = "android")]
pub fn set_name(name: &CStr) {
const PR_SET_NAME: libc::c_int = 15;
// pthread wrapper only appeared in glibc 2.12, so we use syscall
// directly.
unsafe {
libc::prctl(
PR_SET_NAME,
Expand All @@ -132,6 +130,14 @@ impl Thread {
}
}

#[cfg(target_os = "linux")]
pub fn set_name(name: &CStr) {
unsafe {
// Available since glibc 2.12, musl 1.1.16, and uClibc 1.0.20.
libc::pthread_setname_np(libc::pthread_self(), name.as_ptr());
}
}

#[cfg(any(target_os = "freebsd", target_os = "dragonfly", target_os = "openbsd"))]
pub fn set_name(name: &CStr) {
unsafe {
Expand Down