Skip to content

Commit

Permalink
Rollup merge of #123267 - devnexen:thread_get_name_haiku, r=joboet
Browse files Browse the repository at this point in the history
std::thread: adding get_name haiku implementation.

follow-up #123233
  • Loading branch information
workingjubilee committed Mar 31, 2024
2 parents 17737bf + e5c5ed0 commit 2a08f02
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 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,32 @@ impl Thread {
CString::new(name).ok()
}

#[cfg(target_os = "haiku")]
pub fn get_name() -> Option<CString> {
unsafe {
let mut tinfo = mem::MaybeUninit::<libc::thread_info>::uninit();
// See BeOS teams group and threads api.
// https://www.haiku-os.org/legacy-docs/bebook/TheKernelKit_ThreadsAndTeams_Overview.html
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();
let name = slice::from_raw_parts(info.name.as_ptr() as *const u8, info.name.len());
CStr::from_bytes_until_nul(name).map(CStr::to_owned).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 2a08f02

Please sign in to comment.