Skip to content

Commit 2d2563e

Browse files
committed
std::thread: adding freebsd/netbsd to the linux's get_name implementation.
1 parent 7e0ed43 commit 2d2563e

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,9 +225,12 @@ impl Thread {
225225
// Newlib, Emscripten, and VxWorks have no way to set a thread name.
226226
}
227227

228-
#[cfg(target_os = "linux")]
228+
#[cfg(any(target_os = "linux", target_os = "freebsd", target_os = "netbsd",))]
229229
pub fn get_name() -> Option<CString> {
230+
#[cfg(any(target_os = "linux", target_os = "freebsd"))]
230231
const TASK_COMM_LEN: usize = 16;
232+
#[cfg(target_os = "netbsd")]
233+
const TASK_COMM_LEN: usize = 32;
231234
let mut name = vec![0u8; TASK_COMM_LEN];
232235
let res = unsafe {
233236
libc::pthread_getname_np(libc::pthread_self(), name.as_mut_ptr().cast(), name.len())
@@ -254,6 +257,8 @@ impl Thread {
254257

255258
#[cfg(not(any(
256259
target_os = "linux",
260+
target_os = "freebsd",
261+
target_os = "netbsd",
257262
target_os = "macos",
258263
target_os = "ios",
259264
target_os = "tvos",

0 commit comments

Comments
 (0)