Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an async implementation of Queue #324

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

datdenkikniet
Copy link

@datdenkikniet datdenkikniet commented Oct 24, 2022

This PR adds an async version/wrapper around spsc::Queue with 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 heapless for 2 months now and it's worked well so far.


me.value_to_enqueue = Some(failed_enqueue_value);

if !me.producer.register_waker(cx.waker().clone()) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@korken89
Copy link
Contributor

Hi, I think heapless should have an async module in where we can look at adding async specific data structures. Maybe @Dirbaio also has some from embassy that would make sense to put here?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants