pub trait QueueImplementation {
// Required methods
fn create(capacity: usize, item_size: usize) -> QueuePtr;
unsafe fn delete(queue: QueuePtr);
unsafe fn send_to_front(
queue: QueuePtr,
item: *const u8,
timeout_us: Option<u32>,
) -> bool;
unsafe fn send_to_back(
queue: QueuePtr,
item: *const u8,
timeout_us: Option<u32>,
) -> bool;
unsafe fn try_send_to_back_from_isr(
queue: QueuePtr,
item: *const u8,
higher_prio_task_waken: Option<&mut bool>,
) -> bool;
unsafe fn receive(
queue: QueuePtr,
item: *mut u8,
timeout_us: Option<u32>,
) -> bool;
unsafe fn try_receive_from_isr(
queue: QueuePtr,
item: *mut u8,
higher_prio_task_waken: Option<&mut bool>,
) -> bool;
unsafe fn remove(queue: QueuePtr, item: *const u8);
fn messages_waiting(queue: QueuePtr) -> usize;
}Expand description
A queue primitive.
The following snippet demonstrates the boilerplate necessary to implement a queue using the
QueueImplementation trait:
use esp_radio_rtos_driver::{
queue::{QueueImplementation, QueuePtr},
register_queue_implementation,
};
struct MyQueue {
// Queue implementation details
}
impl QueueImplementation for MyQueue {
fn create(capacity: usize, item_size: usize) -> QueuePtr {
unimplemented!()
}
unsafe fn delete(queue: QueuePtr) {
unimplemented!()
}
unsafe fn send_to_front(queue: QueuePtr, item: *const u8, timeout_us: Option<u32>) -> bool {
unimplemented!()
}
unsafe fn send_to_back(queue: QueuePtr, item: *const u8, timeout_us: Option<u32>) -> bool {
unimplemented!()
}
unsafe fn try_send_to_back_from_isr(
queue: QueuePtr,
item: *const u8,
higher_prio_task_waken: Option<&mut bool>,
) -> bool {
unimplemented!()
}
unsafe fn receive(queue: QueuePtr, item: *mut u8, timeout_us: Option<u32>) -> bool {
unimplemented!()
}
unsafe fn try_receive_from_isr(
queue: QueuePtr,
item: *mut u8,
higher_prio_task_waken: Option<&mut bool>,
) -> bool {
unimplemented!()
}
unsafe fn remove(queue: QueuePtr, item: *const u8) {
unimplemented!()
}
fn messages_waiting(queue: QueuePtr) -> usize {
unimplemented!()
}
}
register_queue_implementation!(MyQueue);Required Methods§
Sourcefn create(capacity: usize, item_size: usize) -> QueuePtr
fn create(capacity: usize, item_size: usize) -> QueuePtr
Creates a new, empty queue instance.
The queue must have a capacity for capacity number of item_size byte items.
Sourceunsafe fn send_to_front(
queue: QueuePtr,
item: *const u8,
timeout_us: Option<u32>,
) -> bool
unsafe fn send_to_front( queue: QueuePtr, item: *const u8, timeout_us: Option<u32>, ) -> bool
Enqueues a high-priority item.
If the queue is full, this function will block for the given timeout. If timeout is None, the function will block indefinitely.
This function returns true if the item was successfully enqueued, false otherwise.
§Safety
The caller must ensure that item can be dereferenced and points to an allocation of
a size equal to the queue’s item size.
Sourceunsafe fn send_to_back(
queue: QueuePtr,
item: *const u8,
timeout_us: Option<u32>,
) -> bool
unsafe fn send_to_back( queue: QueuePtr, item: *const u8, timeout_us: Option<u32>, ) -> bool
Enqueues an item.
If the queue is full, this function will block for the given timeout. If timeout is None, the function will block indefinitely.
This function returns true if the item was successfully enqueued, false otherwise.
§Safety
The caller must ensure that item can be dereferenced and points to an allocation of
a size equal to the queue’s item size.
Sourceunsafe fn try_send_to_back_from_isr(
queue: QueuePtr,
item: *const u8,
higher_prio_task_waken: Option<&mut bool>,
) -> bool
unsafe fn try_send_to_back_from_isr( queue: QueuePtr, item: *const u8, higher_prio_task_waken: Option<&mut bool>, ) -> bool
Attempts to enqueues an item.
If the queue is full, this function will immediately return false.
The higher_prio_task_waken parameter is an optional mutable reference to a boolean flag.
If the flag is Some, the implementation may set it to true to request a context switch.
§Safety
The caller must ensure that item can be dereferenced and points to an allocation of
a size equal to the queue’s item size.
Sourceunsafe fn receive(
queue: QueuePtr,
item: *mut u8,
timeout_us: Option<u32>,
) -> bool
unsafe fn receive( queue: QueuePtr, item: *mut u8, timeout_us: Option<u32>, ) -> bool
Dequeues an item from the queue.
If the queue is empty, this function will block for the given timeout. If timeout is None, the function will block indefinitely.
This function returns true if the item was successfully dequeued, false otherwise.
§Safety
The caller must ensure that item can be dereferenced and points to an allocation of
a size equal to the queue’s item size.
Sourceunsafe fn try_receive_from_isr(
queue: QueuePtr,
item: *mut u8,
higher_prio_task_waken: Option<&mut bool>,
) -> bool
unsafe fn try_receive_from_isr( queue: QueuePtr, item: *mut u8, higher_prio_task_waken: Option<&mut bool>, ) -> bool
Attempts to dequeue an item from the queue.
If the queue is empty, this function will return false immediately.
The higher_prio_task_waken parameter is an optional mutable reference to a boolean flag.
If the flag is Some, the implementation may set it to true to request a context switch.
This function returns true if the item was successfully dequeued, false otherwise.
§Safety
The caller must ensure that item can be dereferenced and points to an allocation of
a size equal to the queue’s item size.
Sourceunsafe fn remove(queue: QueuePtr, item: *const u8)
unsafe fn remove(queue: QueuePtr, item: *const u8)
Removes an item from the queue.
§Safety
The caller must ensure that item can be dereferenced and points to an allocation of
a size equal to the queue’s item size.
Sourcefn messages_waiting(queue: QueuePtr) -> usize
fn messages_waiting(queue: QueuePtr) -> usize
Returns the number of messages in the queue.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.