pub struct Queue(/* private fields */);
Expand description
A wrapper around a Zephyr k_queue
object.
Implementations§
Source§impl Queue
impl Queue
Sourcepub const fn new() -> Queue
pub const fn new() -> Queue
Create a new Queue, dynamically allocated.
This Queue can only be used from system threads.
Note: When a Queue is dropped, any messages that have been added to the queue will be leaked.
Sourcepub unsafe fn send(&self, data: *mut c_void)
pub unsafe fn send(&self, data: *mut c_void)
Append an element to the end of a queue.
This adds an element to the given Queue
. Zephyr requires the
first word of this message to be available for the OS to enqueue
the message. See Message
for details on how this can be used
safely.
§Safety
Zephyr has specific requirements on the memory given in data, which can be summarized as:
- The memory must remain valid until after the data is returned, via recv.
- The first
usize
in the pointed data will be mutated by Zephyr to manage structures. - This first field must not be modified by any code while the message is enqueued.
These are easiest to satisfy by ensuring the message is Boxed, and owned by the queue system.
Sourcepub unsafe fn recv<T>(&self, timeout: T) -> *mut c_void
pub unsafe fn recv<T>(&self, timeout: T) -> *mut c_void
Get an element from a queue.
This routine removes the first data item from the Queue
.
The timeout value can be Forever
to block until there is a message, NoWait
to check
and immediately return if there is no message, or a Duration
to indicate a specific
timeout.
§Safety
Once an item is received from a queue, ownership is returned to the caller, and Zephyr no
longer depends on it not being freed, or the first usize
field being for its use.