aboutsummaryrefslogtreecommitdiff
path: root/embassy-executor/src/raw/trace.rs
diff options
context:
space:
mode:
authorKat Perez <[email protected]>2025-05-08 13:40:32 -0400
committerKat Perez <[email protected]>2025-05-08 13:40:32 -0400
commit3b873bb6bb51b9bdac9272b5ec629a6ac54a89f7 (patch)
tree1c5016d8ace52014f62a34cc722b12fc6ef93716 /embassy-executor/src/raw/trace.rs
parent462d04c6d5a0fc6072cf9bdb0faa60da74ff46d2 (diff)
implement TaskRefTrace for tracing-only fields in TaskRef
Diffstat (limited to 'embassy-executor/src/raw/trace.rs')
-rw-r--r--embassy-executor/src/raw/trace.rs52
1 files changed, 52 insertions, 0 deletions
diff --git a/embassy-executor/src/raw/trace.rs b/embassy-executor/src/raw/trace.rs
index b59da0526..b30f23468 100644
--- a/embassy-executor/src/raw/trace.rs
+++ b/embassy-executor/src/raw/trace.rs
@@ -209,6 +209,58 @@ impl TaskTracker {
209 } 209 }
210} 210}
211 211
212/// Extension trait for `TaskRef` that provides tracing functionality.
213///
214/// This trait is only available when the `trace` feature is enabled.
215/// It extends `TaskRef` with methods for accessing and modifying task identifiers
216/// and names, which are useful for debugging, logging, and performance analysis.
217#[cfg(feature = "trace")]
218pub trait TaskRefTrace {
219 /// Get the ID for a task
220 fn as_id(self) -> u32;
221
222 /// Get the name for a task
223 fn name(&self) -> Option<&'static str>;
224
225 /// Set the name for a task
226 fn set_name(&self, name: Option<&'static str>);
227
228 /// Get the ID for a task
229 fn id(&self) -> u32;
230
231 /// Set the ID for a task
232 fn set_id(&self, id: u32);
233}
234
235#[cfg(feature = "trace")]
236impl TaskRefTrace for TaskRef {
237 fn as_id(self) -> u32 {
238 self.ptr.as_ptr() as u32
239 }
240
241 fn name(&self) -> Option<&'static str> {
242 self.header().name
243 }
244
245 fn set_name(&self, name: Option<&'static str>) {
246 unsafe {
247 let header_ptr = self.ptr.as_ptr() as *mut TaskHeader;
248 (*header_ptr).name = name;
249 }
250 }
251
252 fn id(&self) -> u32 {
253 self.header().id
254 }
255
256 fn set_id(&self, id: u32) {
257 unsafe {
258 let header_ptr = self.ptr.as_ptr() as *mut TaskHeader;
259 (*header_ptr).id = id;
260 }
261 }
262}
263
212#[cfg(not(feature = "rtos-trace"))] 264#[cfg(not(feature = "rtos-trace"))]
213extern "Rust" { 265extern "Rust" {
214 /// This callback is called when the executor begins polling. This will always 266 /// This callback is called when the executor begins polling. This will always