Skip to content

Commit e170c9d

Browse files
committed
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 <[email protected]>
1 parent 061ee95 commit e170c9d

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

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

+8-3
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,12 @@ impl Thread {
130130
}
131131
}
132132

133-
#[cfg(any(target_os = "linux", target_os = "freebsd", target_os = "dragonfly"))]
133+
#[cfg(any(
134+
target_os = "linux",
135+
target_os = "freebsd",
136+
target_os = "dragonfly",
137+
target_os = "nuttx"
138+
))]
134139
pub fn set_name(name: &CStr) {
135140
unsafe {
136141
cfg_if::cfg_if! {
@@ -139,7 +144,7 @@ impl Thread {
139144
const TASK_COMM_LEN: usize = 16;
140145
let name = truncate_cstr::<{ TASK_COMM_LEN }>(name);
141146
} else {
142-
// FreeBSD and DragonFly BSD do not enforce length limits.
147+
// FreeBSD, DragonFly, FreeBSD and NuttX do not enforce length limits.
143148
}
144149
};
145150
// Available since glibc 2.12, musl 1.1.16, and uClibc 1.0.20 for Linux,
@@ -150,7 +155,7 @@ impl Thread {
150155
}
151156
}
152157

153-
#[cfg(any(target_os = "openbsd", target_os = "nuttx"))]
158+
#[cfg(target_os = "openbsd")]
154159
pub fn set_name(name: &CStr) {
155160
unsafe {
156161
libc::pthread_set_name_np(libc::pthread_self(), name.as_ptr());

0 commit comments

Comments
 (0)