Skip to content

Commit f12e568

Browse files
committed
zephyr: sync: channel: Fully dynamically allocated
Implement `unbounded` that is able to dynamically allocate the underlying Zephyr queue. This is useful in cases where none of the queue access happens from userspace. Signed-off-by: David Brown <[email protected]>
1 parent 4850c4d commit f12e568

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

zephyr/src/sync/channel.rs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,11 @@ mod counter;
2828
// simply Box the message, leak it out of the box, and give it to Zephyr, and then on receipt, wrap
2929
// it back into a Box, and give it to the recipient.
3030

31-
/// Create a multi-producer multi-consumer channel of unbounded capacity. The messages are
32-
/// allocated individually as "Box", and the queue is managed by the underlying Zephyr queue.
31+
/// Create a multi-producer multi-consumer channel of unbounded capacity, using an existing Queue
32+
/// object.
33+
///
34+
/// The messages are allocated individually as "Box", and the queue is managed by the underlying
35+
/// Zephyr queue.
3336
pub fn unbounded_from<T>(queue: Queue) -> (Sender<T>, Receiver<T>) {
3437
let (s, r) = counter::new(queue);
3538
let s = Sender {
@@ -43,6 +46,18 @@ pub fn unbounded_from<T>(queue: Queue) -> (Sender<T>, Receiver<T>) {
4346
(s, r)
4447
}
4548

49+
/// Create a multi-producer multi-consumer channel of unbounded capacity.
50+
///
51+
/// The messages are allocated individually as "Box". The underlying Zephyr queue will be
52+
/// dynamically allocated.
53+
///
54+
/// **Note**: Currently Drop is not propertly supported on Zephyr. If all senders are dropped, any
55+
/// receivers will likely be blocked forever. Any data that has been queued and not received will
56+
/// be leaked when all receivers have been droped.
57+
pub fn unbounded<T>() -> (Sender<T>, Receiver<T>) {
58+
unbounded_from(Queue::new().unwrap())
59+
}
60+
4661
/// The underlying type for Messages through Zephyr's [`Queue`].
4762
///
4863
/// This wrapper is used internally to wrap user messages through the queue. It is not useful in

0 commit comments

Comments
 (0)