remove name from TaskRegistry and retrieve from task header instead

This commit is contained in:
Kat Perez 2025-05-06 09:27:19 -04:00
parent 61f0f889a0
commit 54b3fb6e7a
2 changed files with 8 additions and 28 deletions

View File

@ -81,7 +81,7 @@
#![allow(unused)] #![allow(unused)]
use crate::raw::{SyncExecutor, TaskRef}; use crate::raw::{SyncExecutor, TaskHeader, TaskRef};
use core::cell::UnsafeCell; use core::cell::UnsafeCell;
use core::sync::atomic::{AtomicUsize, Ordering}; use core::sync::atomic::{AtomicUsize, Ordering};
@ -95,7 +95,6 @@ const MAX_TASKS: usize = 1000;
#[derive(Clone)] #[derive(Clone)]
pub struct TrackedTask { pub struct TrackedTask {
task_id: u32, task_id: u32,
name: Option<&'static str>,
} }
/// A thread-safe registry for tracking tasks in the system. /// A thread-safe registry for tracking tasks in the system.
@ -128,7 +127,7 @@ impl TaskRegistry {
/// ///
/// # Note /// # Note
/// If the registry is full, the task will not be registered. /// If the registry is full, the task will not be registered.
pub fn register(&self, task_id: u32, name: Option<&'static str>) { pub fn register(&self, task_id: u32) {
let count = self.count.load(Ordering::Relaxed); let count = self.count.load(Ordering::Relaxed);
if count < MAX_TASKS { if count < MAX_TASKS {
for i in 0..MAX_TASKS { for i in 0..MAX_TASKS {
@ -136,7 +135,7 @@ impl TaskRegistry {
let slot = &self.tasks[i]; let slot = &self.tasks[i];
let slot_ref = &mut *slot.get(); let slot_ref = &mut *slot.get();
if slot_ref.is_none() { if slot_ref.is_none() {
*slot_ref = Some(TrackedTask { task_id, name }); *slot_ref = Some(TrackedTask { task_id });
self.count.fetch_add(1, Ordering::Relaxed); self.count.fetch_add(1, Ordering::Relaxed);
break; break;
} }
@ -174,28 +173,6 @@ impl TaskRegistry {
(*slot.get()).clone() (*slot.get()).clone()
}) })
} }
/// Retrieves the name of a task with the given ID.
///
/// # Arguments
/// * `task_id` - Unique identifier of the task
///
/// # Returns
/// The name of the task if found and named, or `None` otherwise
pub fn get_task_name(&self, task_id: u32) -> Option<&'static str> {
for i in 0..MAX_TASKS {
unsafe {
let slot = &self.tasks[i];
let slot_ref = &*slot.get();
if let Some(task) = slot_ref {
if task.task_id == task_id {
return task.name;
}
}
}
}
None
}
} }
unsafe impl Sync for TaskRegistry {} unsafe impl Sync for TaskRegistry {}
@ -343,8 +320,10 @@ pub(crate) fn executor_idle(executor: &SyncExecutor) {
impl rtos_trace::RtosTraceOSCallbacks for crate::raw::SyncExecutor { impl rtos_trace::RtosTraceOSCallbacks for crate::raw::SyncExecutor {
fn task_list() { fn task_list() {
for task in TASK_REGISTRY.get_all_tasks() { for task in TASK_REGISTRY.get_all_tasks() {
let task_ref = unsafe { TaskRef::from_ptr(task.task_id as *const TaskHeader) };
let name = task_ref.name().unwrap_or("unnamed\0");
let info = rtos_trace::TaskInfo { let info = rtos_trace::TaskInfo {
name: TASK_REGISTRY.get_task_name(task.task_id).unwrap(), name,
priority: 0, priority: 0,
stack_base: 0, stack_base: 0,
stack_size: 0, stack_size: 0,

View File

@ -171,8 +171,9 @@ impl Spawner {
match task { match task {
Some(task) => { Some(task) => {
task.set_name(Some(name));
let task_id = task.as_ptr() as u32; let task_id = task.as_ptr() as u32;
TASK_REGISTRY.register(task_id, Some(name)); TASK_REGISTRY.register(task_id);
unsafe { self.executor.spawn(task) }; unsafe { self.executor.spawn(task) };
Ok(()) Ok(())