Skip to content

Commit 8e9e877

Browse files
committed
Implement setting thread name for Fuchsia
1 parent 5cc56ac commit 8e9e877

File tree

1 file changed

+30
-4
lines changed

1 file changed

+30
-4
lines changed

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

+30-4
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,23 @@ pub const DEFAULT_MIN_STACK_SIZE: usize = 1024 * 1024;
1313
#[cfg(target_os = "vxworks")]
1414
pub const DEFAULT_MIN_STACK_SIZE: usize = 256 * 1024;
1515

16+
#[cfg(target_os = "fuchsia")]
17+
mod zircon {
18+
type zx_handle_t = u32;
19+
type zx_status_t = i32;
20+
pub const ZX_PROP_NAME: u32 = 3;
21+
22+
extern "C" {
23+
pub fn zx_object_set_property(
24+
handle: zx_handle_t,
25+
property: u32,
26+
value: *const libc::c_void,
27+
value_size: libc::size_t,
28+
) -> zx_status_t;
29+
pub fn zx_thread_self() -> zx_handle_t;
30+
}
31+
}
32+
1633
pub struct Thread {
1734
id: libc::pthread_t,
1835
}
@@ -131,6 +148,19 @@ impl Thread {
131148
}
132149
}
133150

151+
#[cfg(target_os = "fuchsia")]
152+
pub fn set_name(name: &CStr) {
153+
use self::zircon::*;
154+
unsafe {
155+
zx_object_set_property(
156+
zx_thread_self(),
157+
ZX_PROP_NAME,
158+
name.as_ptr() as *const libc::c_void,
159+
libc::strlen(name.as_ptr()),
160+
);
161+
}
162+
}
163+
134164
#[cfg(any(
135165
target_env = "newlib",
136166
target_os = "haiku",
@@ -142,10 +172,6 @@ impl Thread {
142172
pub fn set_name(_name: &CStr) {
143173
// Newlib, Haiku, Emscripten, and VxWorks have no way to set a thread name.
144174
}
145-
#[cfg(target_os = "fuchsia")]
146-
pub fn set_name(_name: &CStr) {
147-
// FIXME: determine whether Fuchsia has a way to set a thread name.
148-
}
149175

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

0 commit comments

Comments
 (0)