pub struct Queue { /* private fields */ }Expand description
Queue types for inter-task communication. Fixed-capacity FIFO queue of raw, fixed-size byte messages.
See the module-level docs above for a full example.
Implementations§
Source§impl Queue
impl Queue
Sourcepub fn new(size: UBaseType, message_size: UBaseType) -> Result<Self>
pub fn new(size: UBaseType, message_size: UBaseType) -> Result<Self>
Creates a queue holding up to size messages of message_size bytes
each. Fails with Error::InvalidQueueSize if either is 0.
§Examples
use osal_rs::os::*;
let queue = Queue::new(4, 4).unwrap();
assert!(Queue::new(0, 4).is_err());Sourcepub fn fetch_with_to_tick(
&self,
buffer: &mut [u8],
time: impl ToTick,
) -> Result<()>
pub fn fetch_with_to_tick( &self, buffer: &mut [u8], time: impl ToTick, ) -> Result<()>
Blocks like Queue::fetch, but accepts any ToTick timeout (e.g.
a core::time::Duration) instead of a raw tick count.
§Examples
use osal_rs::os::*;
use core::time::Duration;
let queue = Queue::new(2, 1).unwrap();
queue.post(&[9u8], 0).unwrap();
let mut buffer = [0u8];
queue.fetch_with_to_tick(&mut buffer, Duration::from_millis(50)).unwrap();
assert_eq!(buffer, [9]);Sourcepub fn post_with_to_tick(&self, item: &[u8], time: impl ToTick) -> Result<()>
pub fn post_with_to_tick(&self, item: &[u8], time: impl ToTick) -> Result<()>
Blocks like Queue::post, but accepts any ToTick timeout (e.g.
a core::time::Duration) instead of a raw tick count.
§Examples
use osal_rs::os::*;
use core::time::Duration;
let queue = Queue::new(2, 1).unwrap();
queue.post_with_to_tick(&[3u8], Duration::from_millis(50)).unwrap();
let mut buffer = [0u8];
queue.fetch(&mut buffer, 0).unwrap();
assert_eq!(buffer, [3]);Methods from Deref<Target = QueueHandle>§
Trait Implementations§
Source§impl Queue for Queue
impl Queue for Queue
Source§fn is_null(&self) -> bool
fn is_null(&self) -> bool
Returns true if this queue is never-initialized-or-already-deleted.
§Examples
use osal_rs::os::*;
let mut queue = Queue::new(2, 1).unwrap();
assert!(!queue.is_null());
queue.delete();
assert!(queue.is_null());Source§fn fetch(&self, buffer: &mut [u8], time: TickType) -> Result<()>
fn fetch(&self, buffer: &mut [u8], time: TickType) -> Result<()>
Blocks until a message is available or time ticks elapse (pass
TickType::MAX to wait forever), copying it into buffer on
success. Fails with Error::Timeout on timeout, or
Error::InvalidQueueSize if buffer is smaller than this queue’s
message size.
§Examples
use osal_rs::os::*;
let queue = Queue::new(2, 4).unwrap();
queue.post(&[1, 2, 3, 4], 0).unwrap();
let mut buffer = [0u8; 4];
queue.fetch(&mut buffer, 100).unwrap();
assert_eq!(buffer, [1, 2, 3, 4]);
// Nothing left to fetch: times out instead of blocking forever.
assert!(queue.fetch(&mut buffer, 10).is_err());Source§fn fetch_from_isr(&self, buffer: &mut [u8]) -> Result<()>
fn fetch_from_isr(&self, buffer: &mut [u8]) -> Result<()>
ISR-safe variant of Queue::fetch. POSIX has no interrupt context
of its own, so this never blocks (trylock instead of lock, and no
timeout parameter); it fails with Error::QueueFull if the mutex
is contended, or Error::Timeout if the queue is simply empty.
§Examples
use osal_rs::os::*;
let queue = Queue::new(2, 1).unwrap();
queue.post(&[5u8], 0).unwrap();
let mut buffer = [0u8];
queue.fetch_from_isr(&mut buffer).unwrap();
assert_eq!(buffer, [5]);Source§fn post(&self, item: &[u8], time: TickType) -> Result<()>
fn post(&self, item: &[u8], time: TickType) -> Result<()>
Blocks until a slot is free or time ticks elapse (pass
TickType::MAX to wait forever), copying item into the queue on
success. Fails with Error::Timeout on timeout, or
Error::InvalidQueueSize if item is smaller than this queue’s
message size.
§Examples
use osal_rs::os::*;
let queue = Queue::new(1, 4).unwrap();
queue.post(&[1, 2, 3, 4], 100).unwrap();
// The single slot is now full: another post times out instead of blocking forever.
assert!(queue.post(&[5, 6, 7, 8], 10).is_err());Source§fn post_from_isr(&self, item: &[u8]) -> Result<()>
fn post_from_isr(&self, item: &[u8]) -> Result<()>
ISR-safe variant of Queue::post. POSIX has no interrupt context of
its own, so this never blocks (trylock instead of lock, and no
timeout parameter); it fails with Error::QueueFull both when the
mutex is contended and when the queue is actually full.
§Examples
use osal_rs::os::*;
let queue = Queue::new(2, 1).unwrap();
queue.post_from_isr(&[1u8]).unwrap();
let mut buffer = [0u8];
queue.fetch(&mut buffer, 0).unwrap();
assert_eq!(buffer, [1]);