diff options
| author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2022-09-12 10:30:01 +0000 |
|---|---|---|
| committer | GitHub <[email protected]> | 2022-09-12 10:30:01 +0000 |
| commit | 809a4a127ba03ab14e8fdd8e8d2dc1e1e51f3522 (patch) | |
| tree | fe38d05d89d79a4044b5d29d460f22afb511e04f | |
| parent | 573c433f64a049d4e0d501df1194c3228aae0863 (diff) | |
| parent | ea5f2c71e063aff9fdc0bde04656f36a3883178d (diff) | |
Merge #946
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 <[email protected]>
| -rw-r--r-- | embassy-sync/src/signal.rs | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/embassy-sync/src/signal.rs b/embassy-sync/src/signal.rs index f6ebeb9b9..34201d03a 100644 --- a/embassy-sync/src/signal.rs +++ b/embassy-sync/src/signal.rs | |||
| @@ -79,7 +79,11 @@ impl<T: Send> Signal<T> { | |||
| 79 | Poll::Pending | 79 | Poll::Pending |
| 80 | } | 80 | } |
| 81 | State::Waiting(w) if w.will_wake(cx.waker()) => Poll::Pending, | 81 | State::Waiting(w) if w.will_wake(cx.waker()) => Poll::Pending, |
| 82 | State::Waiting(_) => panic!("waker overflow"), | 82 | State::Waiting(w) => { |
| 83 | let w = mem::replace(w, cx.waker().clone()); | ||
| 84 | w.wake(); | ||
| 85 | Poll::Pending | ||
| 86 | } | ||
| 83 | State::Signaled(_) => match mem::replace(state, State::None) { | 87 | State::Signaled(_) => match mem::replace(state, State::None) { |
| 84 | State::Signaled(res) => Poll::Ready(res), | 88 | State::Signaled(res) => Poll::Ready(res), |
| 85 | _ => unreachable!(), | 89 | _ => unreachable!(), |
