Skip to content

Commit c2f61e4

Browse files
committed
Update to use critical-section::Mutex instead of mutex::BlockingMutex
This allows the scheduler to better collaborate with existing critical sections
1 parent bc0da32 commit c2f61e4

File tree

2 files changed

+17
-15
lines changed

2 files changed

+17
-15
lines changed

embassy-executor/Cargo.toml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,6 @@ avr-device = { version = "0.7.0", optional = true }
6060
version = "0.3.4"
6161
features = ["no-cache-pad"]
6262

63-
# Note: this is ONLY a dependency when the target does NOT have atomics
64-
[target.'cfg(not(target_has_atomic="ptr"))'.dependencies.mutex]
65-
version = "1.0"
66-
6763
[dev-dependencies]
6864
critical-section = { version = "1.1", features = ["std"] }
6965
trybuild = "1.0"

embassy-executor/src/raw/run_queue.rs

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,12 @@ impl RunQueue {
7070
///
7171
/// `item` must NOT be already enqueued in any queue.
7272
#[inline(always)]
73-
pub(crate) unsafe fn enqueue(&self, task: TaskRef, _: super::state::Token) -> bool {
74-
self.stack.push_was_empty(task)
73+
pub(crate) unsafe fn enqueue(&self, task: TaskRef, _tok: super::state::Token) -> bool {
74+
self.stack.push_was_empty(
75+
task,
76+
#[cfg(not(target_has_atomic = "ptr"))]
77+
_tok,
78+
)
7579
}
7680

7781
/// # Standard atomic runqueue
@@ -153,26 +157,28 @@ fn run_dequeue(taskref: &TaskRef) {
153157
/// A wrapper type that acts like TransferStack by wrapping a normal Stack in a CS mutex
154158
#[cfg(not(target_has_atomic = "ptr"))]
155159
struct MutexTransferStack<T: Linked<cordyceps::stack::Links<T>>> {
156-
inner: mutex::BlockingMutex<mutex::raw_impls::cs::CriticalSectionRawMutex, cordyceps::Stack<T>>,
160+
inner: critical_section::Mutex<core::cell::RefCell<cordyceps::Stack<T>>>,
157161
}
158162

159163
#[cfg(not(target_has_atomic = "ptr"))]
160164
impl<T: Linked<cordyceps::stack::Links<T>>> MutexTransferStack<T> {
161165
const fn new() -> Self {
162166
Self {
163-
inner: mutex::BlockingMutex::new(cordyceps::Stack::new()),
167+
inner: critical_section::Mutex::new(core::cell::RefCell::new(cordyceps::Stack::new())),
164168
}
165169
}
166170

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-
})
171+
fn push_was_empty(&self, item: T::Handle, token: super::state::Token) -> bool {
172+
let mut guard = self.inner.borrow_ref_mut(token);
173+
let is_empty = guard.is_empty();
174+
guard.push(item);
175+
is_empty
173176
}
174177

175178
fn take_all(&self) -> cordyceps::Stack<T> {
176-
self.inner.with_lock(|stack| stack.take_all())
179+
critical_section::with(|cs| {
180+
let mut guard = self.inner.borrow_ref_mut(cs);
181+
guard.take_all()
182+
})
177183
}
178184
}

0 commit comments

Comments
 (0)