implement TaskRefTrace for tracing-only fields in TaskRef

This commit is contained in:
Kat Perez 2025-05-08 13:40:32 -04:00
parent 462d04c6d5
commit 3b873bb6bb
2 changed files with 52 additions and 36 deletions

View File

@ -149,42 +149,6 @@ impl TaskRef {
pub(crate) fn as_ptr(self) -> *const TaskHeader { pub(crate) fn as_ptr(self) -> *const TaskHeader {
self.ptr.as_ptr() self.ptr.as_ptr()
} }
/// Get the ID for a task
#[cfg(feature = "trace")]
pub fn as_id(self) -> u32 {
self.ptr.as_ptr() as u32
}
/// Get the name for a task
#[cfg(feature = "trace")]
pub fn name(&self) -> Option<&'static str> {
self.header().name
}
/// Set the name for a task
#[cfg(feature = "trace")]
pub fn set_name(&self, name: Option<&'static str>) {
unsafe {
let header_ptr = self.ptr.as_ptr() as *mut TaskHeader;
(*header_ptr).name = name;
}
}
/// Get the ID for a task
#[cfg(feature = "trace")]
pub fn id(&self) -> u32 {
self.header().id
}
/// Set the ID for a task
#[cfg(feature = "trace")]
pub fn set_id(&self, id: u32) {
unsafe {
let header_ptr = self.ptr.as_ptr() as *mut TaskHeader;
(*header_ptr).id = id;
}
}
} }
/// Raw storage in which a task can be spawned. /// Raw storage in which a task can be spawned.

View File

@ -209,6 +209,58 @@ impl TaskTracker {
} }
} }
/// Extension trait for `TaskRef` that provides tracing functionality.
///
/// This trait is only available when the `trace` feature is enabled.
/// It extends `TaskRef` with methods for accessing and modifying task identifiers
/// and names, which are useful for debugging, logging, and performance analysis.
#[cfg(feature = "trace")]
pub trait TaskRefTrace {
/// Get the ID for a task
fn as_id(self) -> u32;
/// Get the name for a task
fn name(&self) -> Option<&'static str>;
/// Set the name for a task
fn set_name(&self, name: Option<&'static str>);
/// Get the ID for a task
fn id(&self) -> u32;
/// Set the ID for a task
fn set_id(&self, id: u32);
}
#[cfg(feature = "trace")]
impl TaskRefTrace for TaskRef {
fn as_id(self) -> u32 {
self.ptr.as_ptr() as u32
}
fn name(&self) -> Option<&'static str> {
self.header().name
}
fn set_name(&self, name: Option<&'static str>) {
unsafe {
let header_ptr = self.ptr.as_ptr() as *mut TaskHeader;
(*header_ptr).name = name;
}
}
fn id(&self) -> u32 {
self.header().id
}
fn set_id(&self, id: u32) {
unsafe {
let header_ptr = self.ptr.as_ptr() as *mut TaskHeader;
(*header_ptr).id = id;
}
}
}
#[cfg(not(feature = "rtos-trace"))] #[cfg(not(feature = "rtos-trace"))]
extern "Rust" { extern "Rust" {
/// This callback is called when the executor begins polling. This will always /// This callback is called when the executor begins polling. This will always