Skip to content

Commit da4a1e4

Browse files
committed
Pass &CStr instead of CString.
1 parent a2d67ef commit da4a1e4

File tree

2 files changed

+6
-7
lines changed

2 files changed

+6
-7
lines changed

src/libstd/sys/unix/freertos/thread.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::ffi::CString;
1+
use crate::ffi::CStr;
22
use crate::io;
33
use crate::mem;
44
use crate::ptr;
@@ -18,7 +18,6 @@ const EXITED: usize = 2;
1818
pub const DEFAULT_MIN_STACK_SIZE: usize = 4096;
1919

2020
pub struct Thread {
21-
name: Pin<Box<CString>>,
2221
id: TaskHandle_t,
2322
join_mutex: Arc<Mutex>,
2423
state: Arc<AtomicUsize>,
@@ -29,20 +28,20 @@ unsafe impl Sync for Thread {}
2928

3029
impl Thread {
3130
// unsafe: see thread::Builder::spawn_unchecked for safety requirements
32-
pub unsafe fn new(name: Option<CString>, stack: usize, p: Box<dyn FnOnce()>)
31+
pub unsafe fn new(name: Option<&CStr>, stack: usize, p: Box<dyn FnOnce()>)
3332
-> io::Result<Thread> {
3433
let join_mutex = Arc::new(Mutex::new());
3534
let state = Arc::new(AtomicUsize::new(RUNNING));
3635

3736
let arg = box (join_mutex.clone(), state.clone(), box p);
3837

39-
let name = Box::pin(name.unwrap_or_else(|| CString::from_vec_unchecked(b"rust_thread".to_vec())));
38+
let name = name.unwrap_or_else(|| CStr::from_bytes_with_nul_unchecked(b"\0"));
4039

41-
let mut thread = Thread { name, id: ptr::null_mut(), join_mutex, state };
40+
let mut thread = Thread { id: ptr::null_mut(), join_mutex, state };
4241

4342
let res = xTaskCreate(
4443
thread_start,
45-
thread.name.as_ptr(),
44+
name.as_ptr(),
4645
stack as u32,
4746
Box::into_raw(arg) as *mut libc::c_void,
4847
5,

src/libstd/thread/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -494,7 +494,7 @@ impl Builder {
494494
// returning.
495495
native: Some(imp::Thread::new(
496496
#[cfg(target_os = "freertos")]
497-
my_thread.cname().map(|s| s.to_owned()),
497+
my_thread.cname(),
498498
stack_size,
499499
mem::transmute::<Box<dyn FnOnce() + 'a>, Box<dyn FnOnce() + 'static>>(Box::new(
500500
main,

0 commit comments

Comments
 (0)