Add an async implementation of Queue#324
Open
datdenkikniet wants to merge 2 commits intorust-embedded:mainfrom
Open
Add an async implementation of Queue#324datdenkikniet wants to merge 2 commits intorust-embedded:mainfrom
Queue#324datdenkikniet wants to merge 2 commits intorust-embedded:mainfrom
Conversation
Dirbaio
reviewed
Dec 23, 2022
|
|
||
| me.value_to_enqueue = Some(failed_enqueue_value); | ||
|
|
||
| if !me.producer.register_waker(cx.waker().clone()) { |
Member
There was a problem hiding this comment.
This should replace the previous waker instead of spinning the CPU at 100%.
Also, cloning wakers is moderately expensive in many executors (it does atomic refcount ops. Not in embassy or RTIC though), so it's nice to avoid cloning if possible. The way you do it is:
- If no waker registered, clone and register it.
- If a waker is registered:
- If
old_waker.will_wake(new_waker)do nothing. This saves a clone. - Otherwise, drop the old one, clone the new one and register it.
- If
Contributor
|
Hi, I think |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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 PR adds an async version/wrapper around
spsc::Queuewith fallible interfaces that can be used in sync contexts.Currently it uses a (non-public) single slot queue to store wakers.
We've been running this version of
heaplessfor 2 months now and it's worked well so far.