Skip to content

Commit 9ad6728

Browse files
authored
Unrolled build for rust-lang#123267
Rollup merge of rust-lang#123267 - devnexen:thread_get_name_haiku, r=joboet std::thread: adding get_name haiku implementation. follow-up rust-lang#123233
2 parents 204805a + e5c5ed0 commit 9ad6728

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

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

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

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

0 commit comments

Comments
 (0)