Skip to content

Commit 3d1ec33

Browse files
committed
Do not sleep if at least one task was woken up
1 parent 18b980a commit 3d1ec33

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

async-cortex-m/src/executor.rs

+9
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,11 @@ impl Executor {
6666
let waker =
6767
unsafe { Waker::from_raw(RawWaker::new(&ready as *const _ as *const _, &VTABLE)) };
6868
let val = loop {
69+
let mut task_woken = false;
70+
6971
// advance the main task
7072
if ready.load(Ordering::Acquire) {
73+
task_woken = true;
7174
ready.store(false, Ordering::Release);
7275

7376
let mut cx = Context::from_waker(&waker);
@@ -88,6 +91,7 @@ impl Executor {
8891
// "oneshot": they'll issue a `wake` and then disable themselves to not run again
8992
// until the woken task has made more work
9093
if task.ready.load(Ordering::Acquire) {
94+
task_woken = true;
9195

9296
// we are about to service the task so switch the `ready` flag to `false`
9397
task.ready.store(false, Ordering::Release);
@@ -109,6 +113,11 @@ impl Executor {
109113
}
110114
}
111115

116+
if task_woken {
117+
// If at least one task was woken up, do not sleep, try again
118+
continue;
119+
}
120+
112121
// try to sleep; this will be a no-op if any of the previous tasks generated a SEV or an
113122
// interrupt ran (regardless of whether it generated a wake-up or not)
114123
asm::wfe();

0 commit comments

Comments
 (0)