diff options
Diffstat (limited to 'embassy-executor/src/raw/mod.rs')
| -rw-r--r-- | embassy-executor/src/raw/mod.rs | 70 |
1 files changed, 0 insertions, 70 deletions
diff --git a/embassy-executor/src/raw/mod.rs b/embassy-executor/src/raw/mod.rs index b4adfe01b..882e4605b 100644 --- a/embassy-executor/src/raw/mod.rs +++ b/embassy-executor/src/raw/mod.rs | |||
| @@ -97,76 +97,6 @@ pub(crate) struct TaskHeader { | |||
| 97 | all_tasks_next: AtomicPtr<TaskHeader>, | 97 | all_tasks_next: AtomicPtr<TaskHeader>, |
| 98 | } | 98 | } |
| 99 | 99 | ||
| 100 | /// A thread-safe tracker for all tasks in the system | ||
| 101 | /// | ||
| 102 | /// This struct uses an intrusive linked list approach to track all tasks | ||
| 103 | /// without additional memory allocations. It maintains a global list of | ||
| 104 | /// tasks that can be traversed to find all currently existing tasks. | ||
| 105 | #[cfg(feature = "trace")] | ||
| 106 | pub struct TaskTracker { | ||
| 107 | head: AtomicPtr<TaskHeader>, | ||
| 108 | } | ||
| 109 | |||
| 110 | #[cfg(feature = "trace")] | ||
| 111 | impl TaskTracker { | ||
| 112 | /// Creates a new empty task tracker | ||
| 113 | /// | ||
| 114 | /// Initializes a tracker with no tasks in its list. | ||
| 115 | pub const fn new() -> Self { | ||
| 116 | Self { | ||
| 117 | head: AtomicPtr::new(core::ptr::null_mut()), | ||
| 118 | } | ||
| 119 | } | ||
| 120 | |||
| 121 | /// Adds a task to the tracker | ||
| 122 | /// | ||
| 123 | /// This method inserts a task at the head of the intrusive linked list. | ||
| 124 | /// The operation is thread-safe and lock-free, using atomic operations | ||
| 125 | /// to ensure consistency even when called from different contexts. | ||
| 126 | /// | ||
| 127 | /// # Arguments | ||
| 128 | /// * `task` - The task reference to add to the tracker | ||
| 129 | pub fn add(&self, task: TaskRef) { | ||
| 130 | let task_ptr = task.as_ptr() as *mut TaskHeader; | ||
| 131 | |||
| 132 | loop { | ||
| 133 | let current_head = self.head.load(Ordering::Acquire); | ||
| 134 | unsafe { | ||
| 135 | (*task_ptr).all_tasks_next.store(current_head, Ordering::Relaxed); | ||
| 136 | } | ||
| 137 | |||
| 138 | if self | ||
| 139 | .head | ||
| 140 | .compare_exchange(current_head, task_ptr, Ordering::Release, Ordering::Relaxed) | ||
| 141 | .is_ok() | ||
| 142 | { | ||
| 143 | break; | ||
| 144 | } | ||
| 145 | } | ||
| 146 | } | ||
| 147 | |||
| 148 | /// Performs an operation on each task in the tracker | ||
| 149 | /// | ||
| 150 | /// This method traverses the entire list of tasks and calls the provided | ||
| 151 | /// function for each task. This allows inspecting or processing all tasks | ||
| 152 | /// in the system without modifying the tracker's structure. | ||
| 153 | /// | ||
| 154 | /// # Arguments | ||
| 155 | /// * `f` - A function to call for each task in the tracker | ||
| 156 | pub fn for_each<F>(&self, mut f: F) | ||
| 157 | where | ||
| 158 | F: FnMut(TaskRef), | ||
| 159 | { | ||
| 160 | let mut current = self.head.load(Ordering::Acquire); | ||
| 161 | while !current.is_null() { | ||
| 162 | let task = unsafe { TaskRef::from_ptr(current) }; | ||
| 163 | f(task); | ||
| 164 | |||
| 165 | current = unsafe { (*current).all_tasks_next.load(Ordering::Acquire) }; | ||
| 166 | } | ||
| 167 | } | ||
| 168 | } | ||
| 169 | |||
| 170 | /// This is essentially a `&'static TaskStorage<F>` where the type of the future has been erased. | 100 | /// This is essentially a `&'static TaskStorage<F>` where the type of the future has been erased. |
| 171 | #[derive(Clone, Copy, PartialEq)] | 101 | #[derive(Clone, Copy, PartialEq)] |
| 172 | pub struct TaskRef { | 102 | pub struct TaskRef { |
