fix(maitake): handle spurious WaitCell
polls
#453
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This branch changes the
Wait
future formaitake::sync::WaitCell
tohandle spurious polls correctly. Currently, a
wait_cell::Wait
futureassumes 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 theWait
future willincorrectly complete immediately in that case.
This branch fixes this by replacing the
bool
field inWait
that'sset on first poll with an "event count" stored in the remaining
WaitCell
state bits. Now, when aWait
is created, it loads thecurrent event count, and calls to
wake()
andclose()
increment theevent count. The
Wait
future then checks if the event count has goneup 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 polledbecause the
WaitCell
woke it up, or if it's being polled because someother future decided to poll it. This also has the side benefit of
fixing racy scenarios where the
WaitCell
is woken between when theWait
future is created and when it's polled for the first time.Fixes #449