diff options
| author | David Carlier <devnexen@gmail.com> | 2024-03-31 11:39:06 +0100 |
|---|---|---|
| committer | David Carlier <devnexen@gmail.com> | 2024-03-31 17:47:44 +0100 |
| commit | e5c5ed00a5e8ecf453dca2072d54e51316594a5e (patch) | |
| tree | 3f475052d6fb6ad44b1dc24c30d71467983bbedd /library/std/src/sys | |
| parent | c93b17d6d20a234f21e04804adef7b58a08dd9e4 (diff) | |
| download | rust-e5c5ed00a5e8ecf453dca2072d54e51316594a5e.tar.gz rust-e5c5ed00a5e8ecf453dca2072d54e51316594a5e.zip | |
std::thread: adding get_name haiku implementation.
follow-up #123233
Diffstat (limited to 'library/std/src/sys')
| -rw-r--r-- | library/std/src/sys/pal/unix/thread.rs | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/library/std/src/sys/pal/unix/thread.rs b/library/std/src/sys/pal/unix/thread.rs index 01e3c3cbc6f..77e31d802a3 100644 --- a/library/std/src/sys/pal/unix/thread.rs +++ b/library/std/src/sys/pal/unix/thread.rs @@ -257,6 +257,23 @@ 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", @@ -264,7 +281,8 @@ impl Thread { 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 |
