Skip to content

Commit e08d065

Browse files
committed
Auto merge of rust-lang#123233 - devnexen:thread_get_name_bsd, r=joboet
std::thread: adding freebsd/netbsd to the linux's get_name implementa… …tion.
2 parents 87c4603 + d9e6e56 commit e08d065

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

Diff for: std/src/sys/pal/unix/thread.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -225,9 +225,14 @@ 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(target_os = "linux")]
230231
const TASK_COMM_LEN: usize = 16;
232+
#[cfg(target_os = "freebsd")]
233+
const TASK_COMM_LEN: usize = libc::MAXCOMLEN + 1;
234+
#[cfg(target_os = "netbsd")]
235+
const TASK_COMM_LEN: usize = 32;
231236
let mut name = vec![0u8; TASK_COMM_LEN];
232237
let res = unsafe {
233238
libc::pthread_getname_np(libc::pthread_self(), name.as_mut_ptr().cast(), name.len())
@@ -254,6 +259,8 @@ impl Thread {
254259

255260
#[cfg(not(any(
256261
target_os = "linux",
262+
target_os = "freebsd",
263+
target_os = "netbsd",
257264
target_os = "macos",
258265
target_os = "ios",
259266
target_os = "tvos",

0 commit comments

Comments
 (0)