aboutsummaryrefslogtreecommitdiff
path: root/embassy-executor
diff options
context:
space:
mode:
authorJames Munns <[email protected]>2025-07-02 13:48:32 +0200
committerDario Nieuwenhuis <[email protected]>2025-09-11 14:45:06 +0200
commitdb063945e76a9b62672377ed71e6e833a295a054 (patch)
tree6914e74f638e2e3e367f989990e298afaf52b91a /embassy-executor
parentd88ea8dd2adefba42489173d5119e888ffa73f07 (diff)
Inline the "MutexTransferStack" impl as it is unclear whether it will be merged upstream
Diffstat (limited to 'embassy-executor')
-rw-r--r--embassy-executor/Cargo.toml6
-rw-r--r--embassy-executor/src/raw/run_queue.rs31
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" 81version = "0.3.4"
82# todo: update after https://github.com/hawkw/mycelium/pull/537 is merged 82features = ["no-cache-pad"]
83git = "https://github.com/hawkw/mycelium"
84rev = "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;
9type TransferStack<T> = cordyceps::TransferStack<T>; 9type TransferStack<T> = cordyceps::TransferStack<T>;
10 10
11#[cfg(not(target_has_atomic = "ptr"))] 11#[cfg(not(target_has_atomic = "ptr"))]
12type TransferStack<T> = cordyceps::MutexTransferStack<mutex::raw_impls::cs::CriticalSectionRawMutex, T>; 12type TransferStack<T> = MutexTransferStack<T>;
13 13
14use super::{TaskHeader, TaskRef}; 14use 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"))]
155struct 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"))]
160impl<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}