diff options
| author | Kat Perez <[email protected]> | 2025-05-06 09:59:27 -0400 |
|---|---|---|
| committer | Kat Perez <[email protected]> | 2025-05-06 09:59:27 -0400 |
| commit | f4e0cbb7cc476b171acd0b21448e9bbc848a616d (patch) | |
| tree | c46f373ae9ff017d2a7767e51b769938ec7a09d6 | |
| parent | 54b3fb6e7a12598e0f6299c18a333060d6a3f9c7 (diff) | |
add ID field to TaskHeader
| -rw-r--r-- | embassy-executor/src/raw/mod.rs | 19 | ||||
| -rw-r--r-- | embassy-executor/src/spawner.rs | 1 |
2 files changed, 20 insertions, 0 deletions
diff --git a/embassy-executor/src/raw/mod.rs b/embassy-executor/src/raw/mod.rs index 3f4e06350..075d8a254 100644 --- a/embassy-executor/src/raw/mod.rs +++ b/embassy-executor/src/raw/mod.rs | |||
| @@ -91,6 +91,8 @@ pub(crate) struct TaskHeader { | |||
| 91 | pub(crate) timer_queue_item: timer_queue::TimerQueueItem, | 91 | pub(crate) timer_queue_item: timer_queue::TimerQueueItem, |
| 92 | #[cfg(feature = "trace")] | 92 | #[cfg(feature = "trace")] |
| 93 | pub(crate) name: Option<&'static str>, | 93 | pub(crate) name: Option<&'static str>, |
| 94 | #[cfg(feature = "trace")] | ||
| 95 | pub(crate) id: u32, | ||
| 94 | } | 96 | } |
| 95 | 97 | ||
| 96 | /// This is essentially a `&'static TaskStorage<F>` where the type of the future has been erased. | 98 | /// This is essentially a `&'static TaskStorage<F>` where the type of the future has been erased. |
| @@ -166,6 +168,21 @@ impl TaskRef { | |||
| 166 | (*header_ptr).name = name; | 168 | (*header_ptr).name = name; |
| 167 | } | 169 | } |
| 168 | } | 170 | } |
| 171 | |||
| 172 | /// Get the ID for a task | ||
| 173 | #[cfg(feature = "trace")] | ||
| 174 | pub fn id(&self) -> u32 { | ||
| 175 | self.header().id | ||
| 176 | } | ||
| 177 | |||
| 178 | /// Set the ID for a task | ||
| 179 | #[cfg(feature = "trace")] | ||
| 180 | pub fn set_id(&self, id: u32) { | ||
| 181 | unsafe { | ||
| 182 | let header_ptr = self.ptr.as_ptr() as *mut TaskHeader; | ||
| 183 | (*header_ptr).id = id; | ||
| 184 | } | ||
| 185 | } | ||
| 169 | } | 186 | } |
| 170 | 187 | ||
| 171 | /// Raw storage in which a task can be spawned. | 188 | /// Raw storage in which a task can be spawned. |
| @@ -209,6 +226,8 @@ impl<F: Future + 'static> TaskStorage<F> { | |||
| 209 | timer_queue_item: timer_queue::TimerQueueItem::new(), | 226 | timer_queue_item: timer_queue::TimerQueueItem::new(), |
| 210 | #[cfg(feature = "trace")] | 227 | #[cfg(feature = "trace")] |
| 211 | name: None, | 228 | name: None, |
| 229 | #[cfg(feature = "trace")] | ||
| 230 | id: 0, | ||
| 212 | }, | 231 | }, |
| 213 | future: UninitCell::uninit(), | 232 | future: UninitCell::uninit(), |
| 214 | } | 233 | } |
diff --git a/embassy-executor/src/spawner.rs b/embassy-executor/src/spawner.rs index 40202299f..7f907346d 100644 --- a/embassy-executor/src/spawner.rs +++ b/embassy-executor/src/spawner.rs | |||
| @@ -174,6 +174,7 @@ impl Spawner { | |||
| 174 | task.set_name(Some(name)); | 174 | task.set_name(Some(name)); |
| 175 | let task_id = task.as_ptr() as u32; | 175 | let task_id = task.as_ptr() as u32; |
| 176 | TASK_REGISTRY.register(task_id); | 176 | TASK_REGISTRY.register(task_id); |
| 177 | task.set_id(task_id); | ||
| 177 | 178 | ||
| 178 | unsafe { self.executor.spawn(task) }; | 179 | unsafe { self.executor.spawn(task) }; |
| 179 | Ok(()) | 180 | Ok(()) |
