Skip to content

Commit b0e40bf

Browse files
committed
Auto merge of #62309 - jlevon:62302, r=alexcrichton
provide thread name to OS for Solarish systems Fixes #62302 Passes a Linux bootstrap build. python x.py test src/tools/tidy happy. I tested this with a small test binary that spawns a few threads, and verified that: - on an illumos system lacking the libc function, the binary runs but no OS-level thread names are set - on an illumos system with the feature, the binary runs, and the thread names are visible and correct under tools like MDB, pstack, core dump, etc.
2 parents cf048cc + 6be2d9a commit b0e40bf

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

src/libstd/sys/unix/thread.rs

+14-1
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,21 @@ impl Thread {
122122
name.as_ptr() as *mut libc::c_void);
123123
}
124124
}
125+
126+
#[cfg(target_os = "solaris")]
127+
pub fn set_name(name: &CStr) {
128+
weak! {
129+
fn pthread_setname_np(
130+
libc::pthread_t, *const libc::c_char
131+
) -> libc::c_int
132+
}
133+
134+
if let Some(f) = pthread_setname_np.get() {
135+
unsafe { f(libc::pthread_self(), name.as_ptr()); }
136+
}
137+
}
138+
125139
#[cfg(any(target_env = "newlib",
126-
target_os = "solaris",
127140
target_os = "haiku",
128141
target_os = "l4re",
129142
target_os = "emscripten",

0 commit comments

Comments
 (0)