pub struct SampleQueue { /* private fields */ }Expand description
A queue that never blocks its writer.
Implementations§
Source§impl SampleQueue
impl SampleQueue
Sourcepub fn new(capacity: usize) -> Self
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).
Sourcepub fn with_first_number(capacity: usize, first: u64) -> Self
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.
Sourcepub fn with_deducer(
capacity: usize,
first: u64,
deducer: TimestampDeducer,
) -> Self
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.
Sourcepub fn dropped(&self) -> u64
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.
Sourcepub fn push(&self, s: Sample)
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.
Sourcepub fn push_packed(&self, s: PackedSample)
pub fn push_packed(&self, s: PackedSample)
Add one PackedSample. This never waits.
Sourcepub fn push_many(&self, samples: &[Sample])
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.
Sourcepub fn push_many_packed(&self, samples: &[PackedSample])
pub fn push_many_packed(&self, samples: &[PackedSample])
Add several PackedSamples with one lock, cloning only Arc handles.
Sourcepub fn push_owned(&self, samples: &mut Vec<Sample>)
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.
Sourcepub fn push_owned_packed(&self, samples: &mut Vec<PackedSample>)
pub fn push_owned_packed(&self, samples: &mut Vec<PackedSample>)
Move every PackedSample out of samples into the queue, with one lock.
Sourcepub fn pop(&self, timeout: Duration) -> Option<Sample>
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.
Sourcepub fn pop_packed(&self, timeout: Duration) -> Option<PackedSample>
pub fn pop_packed(&self, timeout: Duration) -> Option<PackedSample>
Take the oldest PackedSample, waiting up to timeout.
Sourcepub fn pop_many(
&self,
out: &mut Vec<Sample>,
max: usize,
timeout: Duration,
) -> usize
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.
Sourcepub fn pop_many_packed(
&self,
out: &mut Vec<PackedSample>,
max: usize,
timeout: Duration,
) -> usize
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.
Sourcepub fn pop_many_numbered(
&self,
out: &mut Vec<Sample>,
max: usize,
timeout: Duration,
) -> (usize, u64)
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.
Sourcepub fn pop_many_numbered_packed(
&self,
out: &mut Vec<PackedSample>,
max: usize,
timeout: Duration,
) -> (usize, u64)
pub fn pop_many_numbered_packed( &self, out: &mut Vec<PackedSample>, max: usize, timeout: Duration, ) -> (usize, u64)
Like SampleQueue::pop_many_numbered, returning PackedSamples.
Sourcepub fn pop_many_full(
&self,
out: &mut Vec<Sample>,
full: &mut Vec<f64>,
max: usize,
timeout: Duration,
) -> (usize, u64)
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.
Sourcepub fn pop_many_full_packed(
&self,
out: &mut Vec<PackedSample>,
full: &mut Vec<f64>,
max: usize,
timeout: Duration,
) -> (usize, u64)
pub fn pop_many_full_packed( &self, out: &mut Vec<PackedSample>, full: &mut Vec<f64>, max: usize, timeout: Duration, ) -> (usize, u64)
Like SampleQueue::pop_many_full, returning PackedSamples.
Sourcepub fn wake(&self)
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.
Sourcepub fn is_closed(&self) -> bool
pub fn is_closed(&self) -> bool
True once SampleQueue::close has run.