Skip to content

Commit 7533e6f

Browse files
committed
zephyr: sync: channel: Panic on drop
Change behavior to panic if all handles are dropped. Add a comment describing this behavior, and the reason behind it. It could also be made to leak, but still should be documented. Signed-off-by: David Brown <[email protected]>
1 parent d9cf393 commit 7533e6f

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

zephyr/src/sync/channel.rs

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,21 @@
2222
//! The requirement for Drop is only strictly true if the IRQ handler calls `try_recv` and drops
2323
//! received message. If the message is *always* sent over another channel or otherwise not
2424
//! dropped, it *might* be safe to use these messages.
25+
//!
26+
//! ## Dropping of Sender/Receiver
27+
//!
28+
//! Crossbeam channels support detecting when all senders or all receivers have been dropped on a
29+
//! channel, which will cause the handles on the other end to error, including waking up current
30+
//! threads waiting on those channels.
31+
//!
32+
//! At this time, this isn't implementable in Zephyr, as there is no API to wake up all threads
33+
//! blocked on a given `k_queue`. As such, this scenario is not supported. What actually happens
34+
//! is that when all senders or receivers on a channel are dropped, operations on the other end of
35+
//! the channel may just block (or queue forever with unbounded queues). If all handles (both
36+
//! sender and receiver) are dropped, the last drop will cause a panic. It maybe be better to just
37+
//! leak the entire channel, as any data associated with the channels would be leaked at this point,
38+
//! including the underlying Zephyr `k_queue`. Until APIs are added to Zephyr to allow the channel
39+
//! information to be safely freed, these can't actually be freed.
2540
2641
extern crate alloc;
2742

@@ -187,15 +202,14 @@ impl<T> Drop for Sender<T> {
187202
SenderFlavor::Unbounded { queue, .. } => {
188203
unsafe {
189204
queue.release(|_| {
190-
crate::printkln!("Release");
191-
true
205+
panic!("Unbounded queues cannot currently be dropped");
192206
})
193207
}
194208
}
195209
SenderFlavor::Bounded(chan) => {
196210
unsafe {
197211
chan.release(|_| {
198-
panic!("Bounded queues cannot be dropped");
212+
panic!("Bounded queues cannot currently be dropped");
199213
})
200214
}
201215
}

0 commit comments

Comments
 (0)