diff --git a/CHANGELOG.md b/CHANGELOG.md index 5c199f894..a236b0eb8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Check https://github.com/esp-rs/esp-idf-hal/pull/529 for details on that change - The `prelude` module is removed. It was anyway only having a handful of types listed in it. And furthermore, there was no `prelude` module for `esp-idf-svc`. - `embassy-sync` updated to V0.7 +- `ThreadSpawnConfiguration::name` changed from `&'static [u8]` to `&'static core::ffi::CStr` as it is actually a `CStr` ### Deprecated - `DB_11` ADC attenuation in favor of `DB_12` for ESP-IDF V5.0+ diff --git a/src/task.rs b/src/task.rs index 0d0546f6f..fcf9be55f 100644 --- a/src/task.rs +++ b/src/task.rs @@ -351,7 +351,7 @@ pub mod thread { } #[derive(Debug)] pub struct ThreadSpawnConfiguration { - pub name: Option<&'static [u8]>, + pub name: Option<&'static CStr>, pub stack_size: usize, pub priority: u8, pub inherit: bool, @@ -410,12 +410,7 @@ pub mod thread { name: if conf.thread_name.is_null() { None } else { - Some(unsafe { - core::slice::from_raw_parts( - conf.thread_name as _, - c_strlen(conf.thread_name.cast()) + 1, - ) - }) + Some(unsafe { CStr::from_ptr(conf.thread_name) }) }, stack_size: conf.stack_size as _, priority: conf.prio as _, @@ -453,11 +448,6 @@ pub mod thread { } fn set_conf(conf: &ThreadSpawnConfiguration) -> Result<(), EspError> { - if let Some(name) = conf.name { - let _str = CStr::from_bytes_with_nul(name) - .map_err(|_e| panic! {"Missing null byte in provided Thread-Name"}); - } - if conf.priority < 1 || conf.priority as u32 >= configMAX_PRIORITIES { panic!("Thread priority {} has to be [1 - 24]", conf.priority); } @@ -466,18 +456,6 @@ pub mod thread { Ok(()) } - - fn c_strlen(c_str: *const u8) -> usize { - let mut offset = 0; - - loop { - if *unsafe { c_str.offset(offset).as_ref() }.unwrap() == 0 { - return offset as _; - } - - offset += 1; - } - } } pub struct CriticalSection(Cell>>, AtomicBool);