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 with_first_number(capacity: usize, first: u64) -> Self

Build a queue whose first pushed sample gets the number first.

The seq feature numbers the samples of an outlet with one counter. A consumer that connects later starts at the current count.

Source

pub fn with_deducer( capacity: usize, first: u64, deducer: TimestampDeducer, ) -> Self

Build a queue that also gives the full timestamp of each sample.

deducer must hold the state after the sample with the number first - 1. SampleQueue::pop_many_full then gives the full timestamps, also after a drop.

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_packed(&self, s: PackedSample)

Add one PackedSample. This never waits.

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 push_many_packed(&self, samples: &[PackedSample])

Add several PackedSamples with one lock, cloning only Arc handles.

Source

pub fn push_owned(&self, samples: &mut Vec<Sample>)

Move every sample out of samples into the queue, with one lock.

The result is the same as SampleQueue::push_many, but no sample is copied. samples is empty after the call and keeps its capacity, so the caller can fill it again with no new allocation.

A queue with a deducer must not use this call, because the samples that the queue drops at once never pass the deducer.

Source

pub fn push_owned_packed(&self, samples: &mut Vec<PackedSample>)

Move every PackedSample out of samples into the queue, with one lock.

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_packed(&self, timeout: Duration) -> Option<PackedSample>

Take the oldest PackedSample, waiting up to timeout.

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 pop_many_packed( &self, out: &mut Vec<PackedSample>, max: usize, timeout: Duration, ) -> usize

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

Source

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

Like SampleQueue::pop_many, and also give the number of the first sample that it took.

The samples that it took have consecutive numbers. With no sample, the number is the one that the next sample gets.

Source

pub fn pop_many_numbered_packed( &self, out: &mut Vec<PackedSample>, max: usize, timeout: Duration, ) -> (usize, u64)

Source

pub fn pop_many_full( &self, out: &mut Vec<Sample>, full: &mut Vec<f64>, max: usize, timeout: Duration, ) -> (usize, u64)

Like SampleQueue::pop_many_numbered, and also add the full timestamp of each sample that it took to the end of full.

A queue with no deducer gives the timestamps of the samples as they are.

Source

pub fn pop_many_full_packed( &self, out: &mut Vec<PackedSample>, full: &mut Vec<f64>, max: usize, timeout: Duration, ) -> (usize, u64)

Source

pub fn wake(&self)

End the current wait of SampleQueue::pop_many_numbered or SampleQueue::pop_many_full at once, with what the queue holds. A session uses it when a request of its consumer arrives.

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 = !

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

fn try_from(value: U) -> Result<T, !>

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.