Skip to main content

Module channel

Module channel 

Source
Expand description

Typed MPMC blocking channel for IPC between kernel tasks and silos.

§Two levels of abstraction

§1. Typed MPMC channel — kernel-internal

channel<T>(capacity) returns a (Sender<T>, Receiver<T>) pair. Both endpoints are cloneable (Multi-Producer / Multi-Consumer). When the last Sender is dropped, all waiting Receivers see Err(ChannelError::Disconnected), and vice-versa.

let (tx, rx) = channel::<u64>(8);
let tx2 = tx.clone();           // second producer
let rx2 = rx.clone();           // second consumer

§2. Symmetric channel — userspace IPC (silo-to-silo)

SyncChan is a symmetric IpcMessage channel: any holder can send or receive. It is stored by ChanId in a global registry and accessed from userspace via SYS_CHAN_* syscalls. Destroyed explicitly via SyncChan::destroy when all userspace handles are closed.

§Blocking guarantee

Both levels use WaitQueue::wait_until — the condition closure is evaluated atomically under the waiter lock, eliminating the classic lost-wakeup race without a polling loop.

§Lock ordering

To avoid deadlock:

  • The queue (buffer) lock is always acquired inside the wait_until closure, and released before wake_one() is called.
  • send_waitq.wake_one() is called outside any recv closure.
  • recv_waitq.wake_one() is called outside any send closure.

Structs§

ChanId
Unique identifier for a SyncChan in the global registry.
Receiver
The receive end of a channel.
Sender
The send end of a channel.
SyncChan
A symmetric bounded channel over IpcMessage, used by the global channel registry for silo-to-silo syscall-level IPC.

Enums§

ChannelError

Functions§

channel
Create a new bounded MPMC channel with the given capacity.
create_channel
Create a new SyncChan with the given capacity and register it.
destroy_channel
Destroy a channel: remove it from the registry and wake all waiters.
get_channel
Look up a channel by ID. Returns a cloned Arc<SyncChan> if found.