-
Notifications
You must be signed in to change notification settings - Fork 223
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
rtic-sync: deal with dropping & re-splitting channels. #1040
base: master
Are you sure you want to change the base?
Conversation
52a2ac5
to
082859b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very nice, thank you! Just some minor comments.
rtic-sync/src/channel.rs
Outdated
pub fn split(&mut self) -> (Sender<'_, T, N>, Receiver<'_, T, N>) { | ||
assert!( | ||
self.readyq.get_mut().is_empty(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since we have &mut channel
here, can't we do self.clear()
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, we could. When writing this felt weird to drop the items in the queue on split
, but not any earlier. Since most callers won't ever re-split()
their queue I figured we could get away with never calling clear
if they do not.
If you think we should clear()
, should we do it in Receiver::drop
too? It just feels kind of arbitrary to drop
leftover items on split()
and not earlier (i.e. Receiver::drop
), but I have no clue what the usual thing to do is, here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have rebased on the latest master
. Any opinions on the above?
f464616
to
2f7b3c1
Compare
2f7b3c1
to
9db2851
Compare
Currently
split
-ing a channel is technically allowed, but there is no non-panic
way of actually doing so.Currently it will either
panic
iffreeq
is full (andreadyq
is empty), or succesfully re-split and always produceErr(NoReceiver)
when sending, and/orpanic
eventually when returning a free slot whilerecv
-ing.Additionally, items in the ready queue are never dropped if the channel is dropped.
This is not a particularly often-used use-case, but that doesn't mean we cannot try fixing it :)
An alternative approach is to just have a
split: bool
in theChannel
and alwayspanic
if that bool is already set, or always callingChannel::clear
whensplit
-ing.To see concrete use-cases that this PR fixes, please check out the introduced tests.