Skip to content

Commit cd3e345

Browse files
committed
std::thread: adding get_name haiku implementation.
follow-up #123233
1 parent c93b17d commit cd3e345

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

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

+20-1
Original file line numberDiff line numberDiff line change
@@ -257,14 +257,33 @@ impl Thread {
257257
CString::new(name).ok()
258258
}
259259

260+
#[cfg(target_os = "haiku")]
261+
pub fn get_name() -> Option<CString> {
262+
let mut name = vec![0u8; libc::B_OS_NAMELENGTH];
263+
unsafe {
264+
let mut tinfo = mem::MaybeUninit::<libc::thread_info>::uninit();
265+
// See BeOS teams group and threads api.
266+
// https://www.haiku-os.org/legacy-docs/bebook/TheKernelKit_ThreadsAndTeams_Overview.html
267+
let thread_self = libc::find_thread(ptr::null_mut());
268+
let res = libc::get_thread_info(thread_self, tinfo.as_mut_ptr());
269+
if res != libc::B_OK {
270+
return None;
271+
}
272+
let info = tinfo.assume_init();
273+
let name = slice::from_raw_parts(info.name.as_ptr() as *const u8, info.name.len());
274+
CStr::from_bytes_until_nul(name).map(CStr::to_owned).ok()
275+
}
276+
}
277+
260278
#[cfg(not(any(
261279
target_os = "linux",
262280
target_os = "freebsd",
263281
target_os = "netbsd",
264282
target_os = "macos",
265283
target_os = "ios",
266284
target_os = "tvos",
267-
target_os = "watchos"
285+
target_os = "watchos",
286+
target_os = "haiku"
268287
)))]
269288
pub fn get_name() -> Option<CString> {
270289
None

0 commit comments

Comments
 (0)