bus: Take the mutex before popping messages for the bus stream

Otherwise a message might arrive between popping, getting None and
locking the mutex for storing the waker. In that case we would never
be woken up.
This commit is contained in:
Sebastian Dröge 2020-01-22 09:21:10 +02:00
parent aa29567171
commit 217bbc3e94

View file

@ -269,11 +269,11 @@ impl Stream for BusStream {
fn poll_next(self: Pin<&mut Self>, ctx: &mut Context) -> Poll<Option<Self::Item>> {
let BusStream(ref bus, ref waker) = *self;
let mut waker = waker.lock().unwrap();
let msg = bus.pop();
if let Some(msg) = msg {
Poll::Ready(Some(msg))
} else {
let mut waker = waker.lock().unwrap();
*waker = Some(ctx.waker().clone());
Poll::Pending
}