diff options
Diffstat (limited to 'embassy-executor')
| -rw-r--r-- | embassy-executor/Cargo.toml | 6 | ||||
| -rw-r--r-- | embassy-executor/src/raw/run_queue.rs | 31 |
2 files changed, 32 insertions, 5 deletions
diff --git a/embassy-executor/Cargo.toml b/embassy-executor/Cargo.toml index 0ea18acbc..01c028704 100644 --- a/embassy-executor/Cargo.toml +++ b/embassy-executor/Cargo.toml | |||
| @@ -78,10 +78,8 @@ avr-device = { version = "0.7.0", optional = true } | |||
| 78 | 78 | ||
| 79 | 79 | ||
| 80 | [dependencies.cordyceps] | 80 | [dependencies.cordyceps] |
| 81 | # version = "0.3.3" | 81 | version = "0.3.4" |
| 82 | # todo: update after https://github.com/hawkw/mycelium/pull/537 is merged | 82 | features = ["no-cache-pad"] |
| 83 | git = "https://github.com/hawkw/mycelium" | ||
| 84 | rev = "e21f9756e7d787a023f2ef1bc7f2159cc7dd26e0" | ||
| 85 | 83 | ||
| 86 | # Note: this is ONLY a dependency when the target does NOT have atomics | 84 | # Note: this is ONLY a dependency when the target does NOT have atomics |
| 87 | [target.'cfg(not(target_has_atomic="ptr"))'.dependencies.mutex] | 85 | [target.'cfg(not(target_has_atomic="ptr"))'.dependencies.mutex] |
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 | } | ||
