pub struct KernelQueue { /* private fields */ }Expand description
A kernel queue for inter-task communication.
Implements io_uring-style ring buffer IPC as specified in ADR-087 Section 7. Features:
- Lock-free send/recv using atomic head/tail pointers
- Zero-copy descriptor-based messaging for shared regions
- Priority support (messages can have Low, Normal, High, Urgent priority)
- Optional WIT schema validation
§Thread Safety
KernelQueue is Send and Sync. Multiple tasks can send to the same queue
concurrently. Receives are typically done by a single consumer task.
Implementations§
Source§impl KernelQueue
impl KernelQueue
Sourcepub fn new(
config: QueueConfig,
region: RegionHandle,
buffer: *mut u8,
buffer_len: usize,
) -> Result<Self>
pub fn new( config: QueueConfig, region: RegionHandle, buffer: *mut u8, buffer_len: usize, ) -> Result<Self>
Sourcepub fn new_heap(config: QueueConfig) -> Result<(Self, Vec<u8>)>
pub fn new_heap(config: QueueConfig) -> Result<(Self, Vec<u8>)>
Create a queue with heap-allocated backing memory.
This is a convenience method for testing and std environments.
Sourcepub fn send_descriptor(
&mut self,
descriptor: &MessageDescriptor,
region_policy: &RegionPolicy,
region_size: usize,
priority: MsgPriority,
) -> Result<()>
pub fn send_descriptor( &mut self, descriptor: &MessageDescriptor, region_policy: &RegionPolicy, region_size: usize, priority: MsgPriority, ) -> Result<()>
Send a zero-copy message via descriptor.
Instead of copying data, this sends a reference to data in a shared region. The receiver must read the data from the shared region using the descriptor.
§Arguments
descriptor- Reference to data in a shared regionregion_policy- Policy of the region referenced by the descriptorregion_size- Size of the regionpriority- Message priority
§Errors
Returns QueueFull if the queue is full.
Returns InvalidDescriptorRegion if the region policy doesn’t allow descriptors.
Returns InvalidParameter if the descriptor references out-of-bounds memory.
§TOCTOU Protection
Only Immutable or AppendOnly regions are allowed. This prevents the sender from modifying the data after sending but before the receiver processes it.
Sourcepub fn recv(&mut self, buf: &mut [u8]) -> Result<usize>
pub fn recv(&mut self, buf: &mut [u8]) -> Result<usize>
Receive a message from the queue (non-blocking).
§Arguments
buf- Buffer to receive the message data
§Returns
On success, returns the number of bytes received. For descriptor messages,
the descriptor is written to buf and you should use MessageDescriptor::from_bytes
to parse it.
§Errors
Returns QueueEmpty if no messages are available.
Sourcepub fn recv_typed(&mut self, buf: &mut [u8]) -> Result<ReceivedMessage>
pub fn recv_typed(&mut self, buf: &mut [u8]) -> Result<ReceivedMessage>
Receive a message, distinguishing between inline data and descriptors.
§Returns
Returns ReceivedMessage which indicates whether the data is inline
or a descriptor reference.
Sourcepub fn config(&self) -> &QueueConfig
pub fn config(&self) -> &QueueConfig
Get the queue configuration.
Sourcepub fn region(&self) -> RegionHandle
pub fn region(&self) -> RegionHandle
Get the backing region handle.
Sourcepub fn send_count(&self) -> u32
pub fn send_count(&self) -> u32
Get the total number of send operations.
Sourcepub fn recv_count(&self) -> u32
pub fn recv_count(&self) -> u32
Get the total number of recv operations.