This branch changes the Wait future for maitake::sync::WaitCell to
handle spurious polls correctly. Currently, a wait_cell::Wait future
assumes that if it's ever polled a second time, that means its waker was
woken. However, there might be other reasons that a stack of futures
containing a Wait is polled again, and the Wait future will
incorrectly complete immediately in that case.
This branch fixes this by replacing the bool field in Wait that's
set on first poll with an "event count" stored in the remaining
WaitCell state bits. Now, when a Wait is created, it loads the
current event count, and calls to wake() and close() increment the
event count. The Wait future then checks if the event count has gone
up when it's polled, rather than just checking if it's ever been polled
before. This allows the Wait future to determine if it is being polled
because the WaitCell woke it up, or if it's being polled because some
other future decided to poll it. This also has the side benefit of
fixing racy scenarios where the WaitCell is woken between when the
Wait future is created and when it's polled for the first time.
This branch changes the
Wait
future formaitake::sync::WaitCell
to handle spurious polls correctly. Currently, await_cell::Wait
future assumes that if it's ever polled a second time, that means its waker was woken. However, there might be other reasons that a stack of futures containing aWait
is polled again, and theWait
future will incorrectly complete immediately in that case.This branch fixes this by replacing the
bool
field inWait
that's set on first poll with an "event count" stored in the remainingWaitCell
state bits. Now, when aWait
is created, it loads the current event count, and calls towake()
andclose()
increment the event count. TheWait
future then checks if the event count has gone up when it's polled, rather than just checking if it's ever been polled before. This allows theWait
future to determine if it is being polled because theWaitCell
woke it up, or if it's being polled because some other future decided to poll it. This also has the side benefit of fixing racy scenarios where theWaitCell
is woken between when theWait
future is created and when it's polled for the first time.Fixes #449