From ea5f2c71e063aff9fdc0bde04656f36a3883178d Mon Sep 17 00:00:00 2001 From: Dario Nieuwenhuis Date: Mon, 12 Sep 2022 12:05:58 +0200 Subject: [PATCH] sync/signal: wake old waker on overflow instead of panicking. 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. --- embassy-sync/src/signal.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/embassy-sync/src/signal.rs b/embassy-sync/src/signal.rs index f6ebeb9b..34201d03 100644 --- a/embassy-sync/src/signal.rs +++ b/embassy-sync/src/signal.rs @@ -79,7 +79,11 @@ impl Signal { 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!(),