Skip to content

AtomicWaker: take and wake #4151

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions embassy-executor/tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,7 @@ fn waking_after_completion_does_not_poll() {
let (executor, trace) = setup();
executor.spawner().spawn(task1(trace.clone(), waker)).unwrap();

unsafe { executor.poll() };
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure what I was thinking here, the task is single shot and exits by the time this poll returns.

waker.wake();
// Task registers waker, then exits
unsafe { executor.poll() };

// Exited task may be waken but is not polled
Expand All @@ -176,7 +175,6 @@ fn waking_after_completion_does_not_poll() {
"pend", // spawning a task pends the executor
"poll task1", //
"pend", // manual wake, gets cleared by poll
"pend", // manual wake, single pend for two wakes
"pend", // respawning a task pends the executor
"poll task1", //
]
Expand Down
2 changes: 2 additions & 0 deletions embassy-sync/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## Unreleased

- AtomicWaker now drops the Waker after waking it.

## 0.6.2 - 2025-01-15

- Add dynamic dispatch variant of `Pipe`.
Expand Down
9 changes: 3 additions & 6 deletions embassy-sync/src/waitqueue/atomic_waker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,9 @@ impl<M: RawMutex> GenericAtomicWaker<M> {

/// Wake the registered waker, if any.
pub fn wake(&self) {
self.waker.lock(|cell| {
if let Some(w) = cell.replace(None) {
w.wake_by_ref();
cell.set(Some(w));
}
})
if let Some(waker) = self.waker.lock(|cell| cell.take()) {
waker.wake();
}
}
}

Expand Down