Skip to main content

SampleQueue

Struct SampleQueue 

Source
pub struct SampleQueue { /* private fields */ }
Expand description

A queue that never blocks its writer.

Implementations§

Source§

impl SampleQueue

Source

pub fn new(capacity: usize) -> Self

Build a queue that holds capacity samples.

A capacity of zero would drop every sample, so the value floors at 1. liblsl floors the same way (src/stream_info_impl.cpp:268).

Source

pub fn capacity(&self) -> usize

How many samples the queue holds when full.

Source

pub fn dropped(&self) -> u64

How many samples the queue has dropped.

Nothing on the wire carries this number. SPEC.md 8.7 records that a reader cannot see a loss, so this exists for a local report only.

Source

pub fn len(&self) -> usize

How many samples are waiting.

Source

pub fn is_empty(&self) -> bool

True when no sample is waiting.

Source

pub fn push(&self, s: Sample)

Add one sample. This never waits.

A full queue loses its oldest sample. The writer carries on, so a slow reader never holds back the source. SPEC.md 8.7.

Source

pub fn push_many(&self, samples: &[Sample])

Add several samples with one lock. This never waits.

The result is the same as one SampleQueue::push for each sample, in order. A full queue loses its oldest samples, and the count of dropped samples grows by the number that the queue lost. The recorded behavior in artifacts/behavior-liblsl.json therefore still holds.

One lock for a block is the difference between a stream that a program can read at 1000 Hz and one that it cannot.

Source

pub fn pop(&self, timeout: Duration) -> Option<Sample>

Take the oldest sample, waiting up to timeout.

Returns None when the timeout passes with nothing waiting, or when the queue is closed and empty.

Source

pub fn pop_many( &self, out: &mut Vec<Sample>, max: usize, timeout: Duration, ) -> usize

Take every sample that waits, up to max, with one lock.

The samples go to the end of out. The call gives how many it added.

The timeout applies to the first sample only. When one sample waits, the call takes what is there and returns. It never waits for max samples, because a program that shows live signals must show what arrived.

A closed and empty queue gives zero.

Source

pub fn close(&self)

Wake every reader and stop the queue.

Source

pub fn is_closed(&self) -> bool

True once SampleQueue::close has run.

Trait Implementations§

Source§

impl Debug for SampleQueue

Source§

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

Formats the value using the given formatter. Read more

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