Skip to content

Commit b442aea

Browse files
committed
std::thread: set_name implementation proposal for vxWorks.
1 parent 60d1465 commit b442aea

File tree

1 file changed

+29
-2
lines changed

1 file changed

+29
-2
lines changed

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

+29-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,12 @@ use crate::mem::{self, ManuallyDrop};
33
use crate::num::NonZero;
44
#[cfg(all(target_os = "linux", target_env = "gnu"))]
55
use crate::sys::weak::dlsym;
6-
#[cfg(any(target_os = "solaris", target_os = "illumos", target_os = "nto"))]
6+
#[cfg(any(
7+
target_os = "solaris",
8+
target_os = "illumos",
9+
target_os = "nto",
10+
target_os = "vxworks"
11+
))]
712
use crate::sys::weak::weak;
813
use crate::sys::{os, stack_overflow};
914
use crate::time::Duration;
@@ -212,12 +217,33 @@ impl Thread {
212217
}
213218
}
214219

220+
#[cfg(target_os = "vxworks")]
221+
pub fn set_name(name: &CStr) {
222+
// FIXME: adding real STATUS type, OK, ERROR ... to libc crate eventually.
223+
weak! {
224+
fn taskNameSet(
225+
libc::TASK_ID, *mut libc::c_char
226+
) -> libc::c_int
227+
}
228+
229+
// We can't assume taskNameSet is necessarily available.
230+
// VX_TASK_NAME_LEN can be found set to 31,
231+
// however older versions can be set to only 10.
232+
// FIXME: if minimum version supported is 7, then let's try 31.
233+
if let Some(f) = taskNameSet.get() {
234+
const VX_TASK_NAME_LEN: usize = 10;
235+
236+
let name = truncate_cstr::<{ VX_TASK_NAME_LEN }>(name);
237+
let status = unsafe { f(libc::taskIdSelf(), name.as_ptr() as *mut libc::c_char) };
238+
debug_assert_eq!(res, 0);
239+
}
240+
}
241+
215242
#[cfg(any(
216243
target_env = "newlib",
217244
target_os = "l4re",
218245
target_os = "emscripten",
219246
target_os = "redox",
220-
target_os = "vxworks",
221247
target_os = "hurd",
222248
target_os = "aix",
223249
))]
@@ -291,6 +317,7 @@ impl Drop for Thread {
291317
target_os = "nto",
292318
target_os = "solaris",
293319
target_os = "illumos",
320+
target_os = "vxworks",
294321
target_vendor = "apple",
295322
))]
296323
fn truncate_cstr<const MAX_WITH_NUL: usize>(cstr: &CStr) -> [libc::c_char; MAX_WITH_NUL] {

0 commit comments

Comments
 (0)