Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement setting thread name for Fuchsia #84589

Merged
merged 2 commits into from
Jul 24, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 30 additions & 4 deletions library/std/src/sys/unix/thread.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,23 @@ pub const DEFAULT_MIN_STACK_SIZE: usize = 1024 * 1024;
#[cfg(target_os = "vxworks")]
pub const DEFAULT_MIN_STACK_SIZE: usize = 256 * 1024;

#[cfg(target_os = "fuchsia")]
mod zircon {
type zx_handle_t = u32;
type zx_status_t = i32;
pub const ZX_PROP_NAME: u32 = 3;

extern "C" {
pub fn zx_object_set_property(
handle: zx_handle_t,
property: u32,
value: *const libc::c_void,
value_size: libc::size_t,
) -> zx_status_t;
pub fn zx_thread_self() -> zx_handle_t;
}
}

pub struct Thread {
id: libc::pthread_t,
}
Expand Down Expand Up @@ -131,6 +148,19 @@ impl Thread {
}
}

#[cfg(target_os = "fuchsia")]
pub fn set_name(name: &CStr) {
use self::zircon::*;
unsafe {
zx_object_set_property(
zx_thread_self(),
ZX_PROP_NAME,
name.as_ptr() as *const libc::c_void,
name.to_bytes().len(),
);
}
}

#[cfg(any(
target_env = "newlib",
target_os = "haiku",
Expand All @@ -142,10 +172,6 @@ impl Thread {
pub fn set_name(_name: &CStr) {
// Newlib, Haiku, Emscripten, and VxWorks have no way to set a thread name.
}
#[cfg(target_os = "fuchsia")]
pub fn set_name(_name: &CStr) {
// FIXME: determine whether Fuchsia has a way to set a thread name.
}

pub fn sleep(dur: Duration) {
let mut secs = dur.as_secs();
Expand Down