diff options
| author | Dario Nieuwenhuis <[email protected]> | 2022-09-12 12:05:58 +0200 |
|---|---|---|
| committer | Dario Nieuwenhuis <[email protected]> | 2022-09-12 12:05:58 +0200 |
| commit | ea5f2c71e063aff9fdc0bde04656f36a3883178d (patch) | |
| tree | fe38d05d89d79a4044b5d29d460f22afb511e04f /embassy-sync | |
| parent | 573c433f64a049d4e0d501df1194c3228aae0863 (diff) | |
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.
Diffstat (limited to 'embassy-sync')
| -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!(), |
