946: sync/signal: wake old waker on overflow instead of panicking. r=Dirbaio a=Dirbaio

This makes behavior consistent with `WakerRegistration`. It allows canceling `wait` in one task and then calling `wait` in another. If two tasks are `wait`ing concurrently the signal will be received by only one of them, randomly.

Co-authored-by: Dario Nieuwenhuis <dirbaio@dirbaio.net>
This commit is contained in:
bors[bot] 2022-09-12 10:30:01 +00:00 committed by GitHub
commit 809a4a127b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -79,7 +79,11 @@ impl<T: Send> Signal<T> {
Poll::Pending
}
State::Waiting(w) if w.will_wake(cx.waker()) => Poll::Pending,
State::Waiting(_) => panic!("waker overflow"),
State::Waiting(w) => {
let w = mem::replace(w, cx.waker().clone());
w.wake();
Poll::Pending
}
State::Signaled(_) => match mem::replace(state, State::None) {
State::Signaled(res) => Poll::Ready(res),
_ => unreachable!(),