diff options
Diffstat (limited to 'embassy-executor/src/spawner.rs')
| -rw-r--r-- | embassy-executor/src/spawner.rs | 37 |
1 files changed, 2 insertions, 35 deletions
diff --git a/embassy-executor/src/spawner.rs b/embassy-executor/src/spawner.rs index a0d246616..6b8db4f8f 100644 --- a/embassy-executor/src/spawner.rs +++ b/embassy-executor/src/spawner.rs | |||
| @@ -22,7 +22,7 @@ use super::raw; | |||
| 22 | /// Once you've invoked a task function and obtained a SpawnToken, you *must* spawn it. | 22 | /// Once you've invoked a task function and obtained a SpawnToken, you *must* spawn it. |
| 23 | #[must_use = "Calling a task function does nothing on its own. You must spawn the returned SpawnToken, typically with Spawner::spawn()"] | 23 | #[must_use = "Calling a task function does nothing on its own. You must spawn the returned SpawnToken, typically with Spawner::spawn()"] |
| 24 | pub struct SpawnToken<S> { | 24 | pub struct SpawnToken<S> { |
| 25 | raw_task: Option<raw::TaskRef>, | 25 | pub(crate) raw_task: Option<raw::TaskRef>, |
| 26 | phantom: PhantomData<*mut S>, | 26 | phantom: PhantomData<*mut S>, |
| 27 | } | 27 | } |
| 28 | 28 | ||
| @@ -103,7 +103,7 @@ impl core::error::Error for SpawnError {} | |||
| 103 | /// If you want to spawn tasks from another thread, use [SendSpawner]. | 103 | /// If you want to spawn tasks from another thread, use [SendSpawner]. |
| 104 | #[derive(Copy, Clone)] | 104 | #[derive(Copy, Clone)] |
| 105 | pub struct Spawner { | 105 | pub struct Spawner { |
| 106 | executor: &'static raw::Executor, | 106 | pub(crate) executor: &'static raw::Executor, |
| 107 | not_send: PhantomData<*mut ()>, | 107 | not_send: PhantomData<*mut ()>, |
| 108 | } | 108 | } |
| 109 | 109 | ||
| @@ -154,39 +154,6 @@ impl Spawner { | |||
| 154 | } | 154 | } |
| 155 | } | 155 | } |
| 156 | 156 | ||
| 157 | /// Spawns a new task with a specified name. | ||
| 158 | /// | ||
| 159 | /// # Arguments | ||
| 160 | /// * `name` - Static string name to associate with the task | ||
| 161 | /// * `token` - Token representing the task to spawn | ||
| 162 | /// | ||
| 163 | /// # Returns | ||
| 164 | /// Result indicating whether the spawn was successful | ||
| 165 | #[cfg(feature = "trace")] | ||
| 166 | pub fn spawn_named<S>(&self, name: &'static str, token: SpawnToken<S>) -> Result<(), SpawnError> { | ||
| 167 | let task = token.raw_task; | ||
| 168 | mem::forget(token); | ||
| 169 | |||
| 170 | match task { | ||
| 171 | Some(task) => { | ||
| 172 | task.set_name(Some(name)); | ||
| 173 | let task_id = task.as_ptr() as u32; | ||
| 174 | task.set_id(task_id); | ||
| 175 | |||
| 176 | unsafe { self.executor.spawn(task) }; | ||
| 177 | Ok(()) | ||
| 178 | } | ||
| 179 | None => Err(SpawnError::Busy), | ||
| 180 | } | ||
| 181 | } | ||
| 182 | |||
| 183 | /// When rtos-trace is disabled, spawn_named falls back to regular spawn. | ||
| 184 | /// This maintains API compatibility while optimizing out the name parameter. | ||
| 185 | #[cfg(not(feature = "trace"))] | ||
| 186 | pub fn spawn_named<S>(&self, _name: &'static str, token: SpawnToken<S>) -> Result<(), SpawnError> { | ||
| 187 | self.spawn(token) | ||
| 188 | } | ||
| 189 | |||
| 190 | // Used by the `embassy_executor_macros::main!` macro to throw an error when spawn | 157 | // Used by the `embassy_executor_macros::main!` macro to throw an error when spawn |
| 191 | // fails. This is here to allow conditional use of `defmt::unwrap!` | 158 | // fails. This is here to allow conditional use of `defmt::unwrap!` |
| 192 | // without introducing a `defmt` feature in the `embassy_executor_macros` package, | 159 | // without introducing a `defmt` feature in the `embassy_executor_macros` package, |
