aboutsummaryrefslogtreecommitdiff
path: root/embassy-executor/src
diff options
context:
space:
mode:
Diffstat (limited to 'embassy-executor/src')
-rw-r--r--embassy-executor/src/raw/mod.rs36
-rw-r--r--embassy-executor/src/raw/trace.rs52
2 files changed, 52 insertions, 36 deletions
diff --git a/embassy-executor/src/raw/mod.rs b/embassy-executor/src/raw/mod.rs
index 882e4605b..e7a27035a 100644
--- a/embassy-executor/src/raw/mod.rs
+++ b/embassy-executor/src/raw/mod.rs
@@ -149,42 +149,6 @@ impl TaskRef {
149 pub(crate) fn as_ptr(self) -> *const TaskHeader { 149 pub(crate) fn as_ptr(self) -> *const TaskHeader {
150 self.ptr.as_ptr() 150 self.ptr.as_ptr()
151 } 151 }
152
153 /// Get the ID for a task
154 #[cfg(feature = "trace")]
155 pub fn as_id(self) -> u32 {
156 self.ptr.as_ptr() as u32
157 }
158
159 /// Get the name for a task
160 #[cfg(feature = "trace")]
161 pub fn name(&self) -> Option<&'static str> {
162 self.header().name
163 }
164
165 /// Set the name for a task
166 #[cfg(feature = "trace")]
167 pub fn set_name(&self, name: Option<&'static str>) {
168 unsafe {
169 let header_ptr = self.ptr.as_ptr() as *mut TaskHeader;
170 (*header_ptr).name = name;
171 }
172 }
173
174 /// Get the ID for a task
175 #[cfg(feature = "trace")]
176 pub fn id(&self) -> u32 {
177 self.header().id
178 }
179
180 /// Set the ID for a task
181 #[cfg(feature = "trace")]
182 pub fn set_id(&self, id: u32) {
183 unsafe {
184 let header_ptr = self.ptr.as_ptr() as *mut TaskHeader;
185 (*header_ptr).id = id;
186 }
187 }
188} 152}
189 153
190/// Raw storage in which a task can be spawned. 154/// Raw storage in which a task can be spawned.
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