move SpawnerTraceExt back into Spawner
This commit is contained in:
parent
e968c47636
commit
dfaab013eb
@ -89,48 +89,6 @@ use rtos_trace::TaskInfo;
|
|||||||
use crate::raw::{SyncExecutor, TaskHeader, TaskRef};
|
use crate::raw::{SyncExecutor, TaskHeader, TaskRef};
|
||||||
use crate::spawner::{SpawnError, SpawnToken, Spawner};
|
use crate::spawner::{SpawnError, SpawnToken, Spawner};
|
||||||
|
|
||||||
/// Extension trait adding tracing capabilities to the Spawner
|
|
||||||
pub trait SpawnerTraceExt {
|
|
||||||
/// Spawns a new task with a specified name.
|
|
||||||
///
|
|
||||||
/// # Arguments
|
|
||||||
/// * `name` - Static string name to associate with the task
|
|
||||||
/// * `token` - Token representing the task to spawn
|
|
||||||
///
|
|
||||||
/// # Returns
|
|
||||||
/// Result indicating whether the spawn was successful
|
|
||||||
fn spawn_named<S>(&self, name: &'static str, token: SpawnToken<S>) -> Result<(), SpawnError>;
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(feature = "trace")]
|
|
||||||
impl SpawnerTraceExt for Spawner {
|
|
||||||
fn spawn_named<S>(&self, name: &'static str, token: SpawnToken<S>) -> Result<(), SpawnError> {
|
|
||||||
let task = token.raw_task;
|
|
||||||
core::mem::forget(token);
|
|
||||||
|
|
||||||
match task {
|
|
||||||
Some(task) => {
|
|
||||||
task.set_name(Some(name));
|
|
||||||
let task_id = task.as_ptr() as u32;
|
|
||||||
task.set_id(task_id);
|
|
||||||
|
|
||||||
unsafe { self.executor.spawn(task) };
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
None => Err(SpawnError::Busy),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// When trace is disabled, spawn_named falls back to regular spawn.
|
|
||||||
/// This maintains API compatibility while optimizing out the name parameter.
|
|
||||||
#[cfg(not(feature = "trace"))]
|
|
||||||
impl SpawnerTraceExt for Spawner {
|
|
||||||
fn spawn_named<S>(&self, _name: &'static str, token: SpawnToken<S>) -> Result<(), SpawnError> {
|
|
||||||
self.spawn(token)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Global task tracker instance
|
/// Global task tracker instance
|
||||||
///
|
///
|
||||||
/// This static provides access to the global task tracker which maintains
|
/// This static provides access to the global task tracker which maintains
|
||||||
|
|||||||
@ -6,6 +6,9 @@ use core::task::Poll;
|
|||||||
|
|
||||||
use super::raw;
|
use super::raw;
|
||||||
|
|
||||||
|
#[cfg(feature = "trace")]
|
||||||
|
use crate::raw::trace::TaskRefTrace;
|
||||||
|
|
||||||
/// Token to spawn a newly-created task in an executor.
|
/// Token to spawn a newly-created task in an executor.
|
||||||
///
|
///
|
||||||
/// When calling a task function (like `#[embassy_executor::task] async fn my_task() { ... }`), the returned
|
/// When calling a task function (like `#[embassy_executor::task] async fn my_task() { ... }`), the returned
|
||||||
@ -180,6 +183,53 @@ impl Spawner {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Extension trait adding tracing capabilities to the Spawner
|
||||||
|
///
|
||||||
|
/// This trait provides an additional method to spawn tasks with an associated name,
|
||||||
|
/// which can be useful for debugging and tracing purposes.
|
||||||
|
pub trait SpawnerTraceExt {
|
||||||
|
/// Spawns a new task with a specified name.
|
||||||
|
///
|
||||||
|
/// # Arguments
|
||||||
|
/// * `name` - Static string name to associate with the task
|
||||||
|
/// * `token` - Token representing the task to spawn
|
||||||
|
///
|
||||||
|
/// # Returns
|
||||||
|
/// Result indicating whether the spawn was successful
|
||||||
|
fn spawn_named<S>(&self, name: &'static str, token: SpawnToken<S>) -> Result<(), SpawnError>;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Implementation of the SpawnerTraceExt trait for Spawner when trace is enabled
|
||||||
|
#[cfg(feature = "trace")]
|
||||||
|
impl SpawnerTraceExt for Spawner {
|
||||||
|
fn spawn_named<S>(&self, name: &'static str, token: SpawnToken<S>) -> Result<(), SpawnError> {
|
||||||
|
let task = token.raw_task;
|
||||||
|
core::mem::forget(token);
|
||||||
|
|
||||||
|
match task {
|
||||||
|
Some(task) => {
|
||||||
|
// Set the name and ID when trace is enabled
|
||||||
|
task.set_name(Some(name));
|
||||||
|
let task_id = task.as_ptr() as u32;
|
||||||
|
task.set_id(task_id);
|
||||||
|
|
||||||
|
unsafe { self.executor.spawn(task) };
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
None => Err(SpawnError::Busy),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Implementation of the SpawnerTraceExt trait for Spawner when trace is disabled
|
||||||
|
#[cfg(not(feature = "trace"))]
|
||||||
|
impl SpawnerTraceExt for Spawner {
|
||||||
|
fn spawn_named<S>(&self, _name: &'static str, token: SpawnToken<S>) -> Result<(), SpawnError> {
|
||||||
|
// When trace is disabled, just forward to regular spawn and ignore the name
|
||||||
|
self.spawn(token)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Handle to spawn tasks into an executor from any thread.
|
/// Handle to spawn tasks into an executor from any thread.
|
||||||
///
|
///
|
||||||
/// This Spawner can be used from any thread (it is Send), but it can
|
/// This Spawner can be used from any thread (it is Send), but it can
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user