Skip to content

Commit

Permalink
std::thread: adding get_name haiku implementation.
Browse files Browse the repository at this point in the history
follow-up #123233
  • Loading branch information
devnexen committed Mar 31, 2024
1 parent c93b17d commit baed5e0
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion library/std/src/sys/pal/unix/thread.rs
Original file line number Diff line number Diff line change
Expand Up @@ -257,14 +257,31 @@ impl Thread {
CString::new(name).ok()
}

#[cfg(target_os = "haiku")]
pub fn get_name() -> Option<CString> {
let mut name = vec![0u8; libc::B_OS_NAMELENGTH];
unsafe {
let mut tinfo = mem::MaybeUninit::<libc::thread_info>::uninit();
let thread_self = libc::find_thread(ptr::null_mut());
let res = libc::get_thread_info(thread_self, tinfo.as_mut_ptr());
if res != libc::B_OK {
return None;
}
let info = tinfo.assume_init();
name = info.name.iter().map(|&c| c as u8).collect();
CString::new(name).ok()
}
}

#[cfg(not(any(
target_os = "linux",
target_os = "freebsd",
target_os = "netbsd",
target_os = "macos",
target_os = "ios",
target_os = "tvos",
target_os = "watchos"
target_os = "watchos",
target_os = "haiku"
)))]
pub fn get_name() -> Option<CString> {
None
Expand Down

0 comments on commit baed5e0

Please sign in to comment.