Skip to content

zerocopy_channel fixed channel and borrowed sender/receiver #4299

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

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

Conversation

mkj
Copy link
Contributor

@mkj mkj commented Jun 10, 2025

The first commit implements a borrowed sender/receiver for Channel. This allows sending from the Channel itself, and also could be an alternative to MPSC such as in #2322. Currently there isn't any async sender()/receiver() equivalent, since that'd need a bounded number of wakers and seems like complication.
The extra bools in the struct don't add any size, the only overhead will be some bit flips on construction/drop.

The second commit allows having a FixedChannel with local storage. I think the use of UnsafeCell is safe, but it would be good if someone with more unsafe experience could take a look over it. new_cloned() name is a bit arbitrary.

@mkj mkj force-pushed the matt/zcchannel branch from ba5bd98 to 0680da4 Compare June 10, 2025 10:15
mkj added 2 commits June 11, 2025 12:25
This allows borrowing a Channel between multiple senders or receivers,
but not simultaneously. It also makes it possible to send() or receive()
on a Channel (by taking the Sender or Receiver temporarily).

Only one borrow is allowed at a time, checked at runtime.

.split() remains as it was previously, since it takes a mut reference.
This is an equivalent of zerocopy_channel::Channel with a fixed internal
buffer, similar to embassy_sync::Channel.

zero_copychannel::Channel and FixedChannel share a common ChannelInner
@mkj mkj force-pushed the matt/zcchannel branch from 0680da4 to e9db18b Compare June 11, 2025 04:28
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.

1 participant