diff options
| author | Kat Perez <[email protected]> | 2025-04-29 08:49:19 -0400 |
|---|---|---|
| committer | Kat Perez <[email protected]> | 2025-05-06 08:27:46 -0400 |
| commit | f8f9c38b2e2527c6e3b8396e06fbb18fc1ce2a1c (patch) | |
| tree | 3902372deb606a037a6c2cda5b53bf7c7dc37962 /embassy-executor/src/spawner.rs | |
| parent | 966914f4654f30f13964f90c1e2bd491f1105c6f (diff) | |
add a task registry to tracing infrastructure
Diffstat (limited to 'embassy-executor/src/spawner.rs')
| -rw-r--r-- | embassy-executor/src/spawner.rs | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/embassy-executor/src/spawner.rs b/embassy-executor/src/spawner.rs index ff243081c..ea754341b 100644 --- a/embassy-executor/src/spawner.rs +++ b/embassy-executor/src/spawner.rs | |||
| @@ -5,6 +5,8 @@ use core::sync::atomic::Ordering; | |||
| 5 | use core::task::Poll; | 5 | use core::task::Poll; |
| 6 | 6 | ||
| 7 | use super::raw; | 7 | use super::raw; |
| 8 | #[cfg(feature = "rtos-trace")] | ||
| 9 | use super::raw::trace::TASK_REGISTRY; | ||
| 8 | 10 | ||
| 9 | /// Token to spawn a newly-created task in an executor. | 11 | /// Token to spawn a newly-created task in an executor. |
| 10 | /// | 12 | /// |
| @@ -154,6 +156,31 @@ impl Spawner { | |||
| 154 | } | 156 | } |
| 155 | } | 157 | } |
| 156 | 158 | ||
| 159 | /// Spawns a new task with a specified name. | ||
| 160 | /// | ||
| 161 | /// # Arguments | ||
| 162 | /// * `name` - Static string name to associate with the task | ||
| 163 | /// * `token` - Token representing the task to spawn | ||
| 164 | /// | ||
| 165 | /// # Returns | ||
| 166 | /// Result indicating whether the spawn was successful | ||
| 167 | #[cfg(feature = "rtos-trace")] | ||
| 168 | pub fn spawn_named<S>(&self, name: &'static str, token: SpawnToken<S>) -> Result<(), SpawnError> { | ||
| 169 | let task = token.raw_task; | ||
| 170 | mem::forget(token); | ||
| 171 | |||
| 172 | match task { | ||
| 173 | Some(task) => { | ||
| 174 | let task_id = task.as_ptr() as u32; | ||
| 175 | TASK_REGISTRY.register(task_id, Some(name)); | ||
| 176 | |||
| 177 | unsafe { self.executor.spawn(task) }; | ||
| 178 | Ok(()) | ||
| 179 | } | ||
| 180 | None => Err(SpawnError::Busy), | ||
| 181 | } | ||
| 182 | } | ||
| 183 | |||
| 157 | // Used by the `embassy_executor_macros::main!` macro to throw an error when spawn | 184 | // Used by the `embassy_executor_macros::main!` macro to throw an error when spawn |
| 158 | // fails. This is here to allow conditional use of `defmt::unwrap!` | 185 | // fails. This is here to allow conditional use of `defmt::unwrap!` |
| 159 | // without introducing a `defmt` feature in the `embassy_executor_macros` package, | 186 | // without introducing a `defmt` feature in the `embassy_executor_macros` package, |
