diff options
Diffstat (limited to 'embassy-executor/src')
| -rw-r--r-- | embassy-executor/src/raw/run_queue.rs | 31 |
1 files changed, 30 insertions, 1 deletions
diff --git a/embassy-executor/src/raw/run_queue.rs b/embassy-executor/src/raw/run_queue.rs index c6c7d7109..5fd703aad 100644 --- a/embassy-executor/src/raw/run_queue.rs +++ b/embassy-executor/src/raw/run_queue.rs | |||
| @@ -9,7 +9,7 @@ use cordyceps::SortedList; | |||
| 9 | type TransferStack<T> = cordyceps::TransferStack<T>; | 9 | type TransferStack<T> = cordyceps::TransferStack<T>; |
| 10 | 10 | ||
| 11 | #[cfg(not(target_has_atomic = "ptr"))] | 11 | #[cfg(not(target_has_atomic = "ptr"))] |
| 12 | type TransferStack<T> = cordyceps::MutexTransferStack<mutex::raw_impls::cs::CriticalSectionRawMutex, T>; | 12 | type TransferStack<T> = MutexTransferStack<T>; |
| 13 | 13 | ||
| 14 | use super::{TaskHeader, TaskRef}; | 14 | use super::{TaskHeader, TaskRef}; |
| 15 | 15 | ||
| @@ -149,3 +149,32 @@ fn run_dequeue(taskref: &TaskRef) { | |||
| 149 | taskref.header().state.run_dequeue(cs); | 149 | taskref.header().state.run_dequeue(cs); |
| 150 | }) | 150 | }) |
| 151 | } | 151 | } |
| 152 | |||
| 153 | /// A wrapper type that acts like TransferStack by wrapping a normal Stack in a CS mutex | ||
| 154 | #[cfg(not(target_has_atomic="ptr"))] | ||
| 155 | struct MutexTransferStack<T: Linked<cordyceps::stack::Links<T>>> { | ||
| 156 | inner: mutex::BlockingMutex<mutex::raw_impls::cs::CriticalSectionRawMutex, cordyceps::Stack<T>>, | ||
| 157 | } | ||
| 158 | |||
| 159 | #[cfg(not(target_has_atomic="ptr"))] | ||
| 160 | impl<T: Linked<cordyceps::stack::Links<T>>> MutexTransferStack<T> { | ||
| 161 | const fn new() -> Self { | ||
| 162 | Self { | ||
| 163 | inner: mutex::BlockingMutex::new(cordyceps::Stack::new()), | ||
| 164 | } | ||
| 165 | } | ||
| 166 | |||
| 167 | fn push_was_empty(&self, item: T::Handle) -> bool { | ||
| 168 | self.inner.with_lock(|stack| { | ||
| 169 | let is_empty = stack.is_empty(); | ||
| 170 | stack.push(item); | ||
| 171 | is_empty | ||
| 172 | }) | ||
| 173 | } | ||
| 174 | |||
| 175 | fn take_all(&self) -> cordyceps::Stack<T> { | ||
| 176 | self.inner.with_lock(|stack| { | ||
| 177 | stack.take_all() | ||
| 178 | }) | ||
| 179 | } | ||
| 180 | } | ||
