Skip to main content

Queue

Struct Queue 

Source
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

Source

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());
Source

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]);
Source

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>§

Source

pub fn is_empty(&self) -> bool

Returns true if this handle is still in its never-initialized (or already-deleted) state, i.e. both the mutex and condition variable are all-zero.

§Examples
use osal_rs::os::types::ClockMonotonicHandle;

assert!(ClockMonotonicHandle::default().is_empty());

Trait Implementations§

Source§

impl Debug for Queue

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Deref for Queue

Source§

type Target = ClockMonotonicHandle

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl Display for Queue

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Drop for Queue

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more
Source§

impl Queue for Queue

Source§

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<()>

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<()>

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<()>

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<()>

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]);
Source§

fn delete(&mut self)

Destroys the underlying pthread objects and resets this queue to its “null” state. Safe to call more than once, and called automatically on Drop if not called explicitly.

§Examples
use osal_rs::os::*;

let mut queue = Queue::new(2, 1).unwrap();
queue.delete();
assert!(queue.is_null());
Source§

impl Send for Queue

Source§

impl Sync for Queue

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.