Skip to content

Commit baed5e0

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

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

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

+18-1
Original file line numberDiff line numberDiff line change
@@ -257,14 +257,31 @@ 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+
let thread_self = libc::find_thread(ptr::null_mut());
266+
let res = libc::get_thread_info(thread_self, tinfo.as_mut_ptr());
267+
if res != libc::B_OK {
268+
return None;
269+
}
270+
let info = tinfo.assume_init();
271+
name = info.name.iter().map(|&c| c as u8).collect();
272+
CString::new(name).ok()
273+
}
274+
}
275+
260276
#[cfg(not(any(
261277
target_os = "linux",
262278
target_os = "freebsd",
263279
target_os = "netbsd",
264280
target_os = "macos",
265281
target_os = "ios",
266282
target_os = "tvos",
267-
target_os = "watchos"
283+
target_os = "watchos",
284+
target_os = "haiku"
268285
)))]
269286
pub fn get_name() -> Option<CString> {
270287
None

0 commit comments

Comments
 (0)