Skip to content

Commit

Permalink
std::thread: set_name implementation proposal for vxWorks.
Browse files Browse the repository at this point in the history
  • Loading branch information
devnexen committed Aug 6, 2024
1 parent 60d1465 commit b442aea
Showing 1 changed file with 29 additions and 2 deletions.
31 changes: 29 additions & 2 deletions library/std/src/sys/pal/unix/thread.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@ use crate::mem::{self, ManuallyDrop};
use crate::num::NonZero;
#[cfg(all(target_os = "linux", target_env = "gnu"))]
use crate::sys::weak::dlsym;
#[cfg(any(target_os = "solaris", target_os = "illumos", target_os = "nto"))]
#[cfg(any(
target_os = "solaris",
target_os = "illumos",
target_os = "nto",
target_os = "vxworks"
))]
use crate::sys::weak::weak;
use crate::sys::{os, stack_overflow};
use crate::time::Duration;
Expand Down Expand Up @@ -212,12 +217,33 @@ impl Thread {
}
}

#[cfg(target_os = "vxworks")]
pub fn set_name(name: &CStr) {
// FIXME: adding real STATUS type, OK, ERROR ... to libc crate eventually.
weak! {
fn taskNameSet(
libc::TASK_ID, *mut libc::c_char
) -> libc::c_int
}

// We can't assume taskNameSet is necessarily available.
// VX_TASK_NAME_LEN can be found set to 31,
// however older versions can be set to only 10.
// FIXME: if minimum version supported is 7, then let's try 31.
if let Some(f) = taskNameSet.get() {
const VX_TASK_NAME_LEN: usize = 10;

let name = truncate_cstr::<{ VX_TASK_NAME_LEN }>(name);
let status = unsafe { f(libc::taskIdSelf(), name.as_ptr() as *mut libc::c_char) };
debug_assert_eq!(res, 0);
}
}

#[cfg(any(
target_env = "newlib",
target_os = "l4re",
target_os = "emscripten",
target_os = "redox",
target_os = "vxworks",
target_os = "hurd",
target_os = "aix",
))]
Expand Down Expand Up @@ -291,6 +317,7 @@ impl Drop for Thread {
target_os = "nto",
target_os = "solaris",
target_os = "illumos",
target_os = "vxworks",
target_vendor = "apple",
))]
fn truncate_cstr<const MAX_WITH_NUL: usize>(cstr: &CStr) -> [libc::c_char; MAX_WITH_NUL] {
Expand Down

0 comments on commit b442aea

Please sign in to comment.