Fix set_name in thread mod for NuttX
Replace `pthread_set_name_np` with `pthread_setname_np` for NuttX in the `set_name` function, this change aligns the implementation with the correct API available on NuttX This patch ensures thread naming works correctly on NuttX platforms. Signed-off-by: Huang Qi <huangqi3@xiaomi.com>
This commit is contained in:
parent
061ee95ce1
commit
e170c9dec0
1 changed files with 8 additions and 3 deletions
|
@ -130,7 +130,12 @@ impl Thread {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(any(target_os = "linux", target_os = "freebsd", target_os = "dragonfly"))]
|
#[cfg(any(
|
||||||
|
target_os = "linux",
|
||||||
|
target_os = "freebsd",
|
||||||
|
target_os = "dragonfly",
|
||||||
|
target_os = "nuttx"
|
||||||
|
))]
|
||||||
pub fn set_name(name: &CStr) {
|
pub fn set_name(name: &CStr) {
|
||||||
unsafe {
|
unsafe {
|
||||||
cfg_if::cfg_if! {
|
cfg_if::cfg_if! {
|
||||||
|
@ -139,7 +144,7 @@ impl Thread {
|
||||||
const TASK_COMM_LEN: usize = 16;
|
const TASK_COMM_LEN: usize = 16;
|
||||||
let name = truncate_cstr::<{ TASK_COMM_LEN }>(name);
|
let name = truncate_cstr::<{ TASK_COMM_LEN }>(name);
|
||||||
} else {
|
} else {
|
||||||
// FreeBSD and DragonFly BSD do not enforce length limits.
|
// FreeBSD, DragonFly, FreeBSD and NuttX do not enforce length limits.
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
// Available since glibc 2.12, musl 1.1.16, and uClibc 1.0.20 for Linux,
|
// Available since glibc 2.12, musl 1.1.16, and uClibc 1.0.20 for Linux,
|
||||||
|
@ -150,7 +155,7 @@ impl Thread {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(any(target_os = "openbsd", target_os = "nuttx"))]
|
#[cfg(target_os = "openbsd")]
|
||||||
pub fn set_name(name: &CStr) {
|
pub fn set_name(name: &CStr) {
|
||||||
unsafe {
|
unsafe {
|
||||||
libc::pthread_set_name_np(libc::pthread_self(), name.as_ptr());
|
libc::pthread_set_name_np(libc::pthread_self(), name.as_ptr());
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue