pub struct BBBuffer<const N: usize> { /* private fields */ }
Expand description
A backing structure for a BBQueue. Can be used to create either a BBQueue or a split Producer/Consumer pair
Implementations§
source§impl<'a, const N: usize> BBBuffer<N>
impl<'a, const N: usize> BBBuffer<N>
sourcepub fn try_split(&'a self) -> Result<(Producer<'a, N>, Consumer<'a, N>)>
pub fn try_split(&'a self) -> Result<(Producer<'a, N>, Consumer<'a, N>)>
Attempt to split the BBBuffer
into Consumer
and Producer
halves to gain access to the
buffer. If buffer has already been split, an error will be returned.
NOTE: When splitting, the underlying buffer will be explicitly initialized
to zero. This may take a measurable amount of time, depending on the size
of the buffer. This is necessary to prevent undefined behavior. If the buffer
is placed at static
scope within the .bss
region, the explicit initialization
will be elided (as it is already performed as part of memory initialization)
NOTE: If the thumbv6
feature is selected, this function takes a short critical section
while splitting.
use bbqueue::BBBuffer;
// Create and split a new buffer
let buffer: BBBuffer<6> = BBBuffer::new();
let (prod, cons) = buffer.try_split().unwrap();
// Not possible to split twice
assert!(buffer.try_split().is_err());
sourcepub fn try_split_framed(
&'a self
) -> Result<(FrameProducer<'a, N>, FrameConsumer<'a, N>)>
pub fn try_split_framed( &'a self ) -> Result<(FrameProducer<'a, N>, FrameConsumer<'a, N>)>
Attempt to split the BBBuffer
into FrameConsumer
and FrameProducer
halves
to gain access to the buffer. If buffer has already been split, an error
will be returned.
NOTE: When splitting, the underlying buffer will be explicitly initialized
to zero. This may take a measurable amount of time, depending on the size
of the buffer. This is necessary to prevent undefined behavior. If the buffer
is placed at static
scope within the .bss
region, the explicit initialization
will be elided (as it is already performed as part of memory initialization)
NOTE: If the thumbv6
feature is selected, this function takes a short critical
section while splitting.
sourcepub fn try_release(
&'a self,
prod: Producer<'a, N>,
cons: Consumer<'a, N>
) -> CoreResult<(), (Producer<'a, N>, Consumer<'a, N>)>
pub fn try_release( &'a self, prod: Producer<'a, N>, cons: Consumer<'a, N> ) -> CoreResult<(), (Producer<'a, N>, Consumer<'a, N>)>
Attempt to release the Producer and Consumer
This re-initializes the buffer so it may be split in a different mode at a later time. There must be no read or write grants active, or an error will be returned.
The Producer
and Consumer
must be from THIS BBBuffer
, or an error will
be returned.
use bbqueue::BBBuffer;
// Create and split a new buffer
let buffer: BBBuffer<6> = BBBuffer::new();
let (prod, cons) = buffer.try_split().unwrap();
// Not possible to split twice
assert!(buffer.try_split().is_err());
// Release the producer and consumer
assert!(buffer.try_release(prod, cons).is_ok());
// Split the buffer in framed mode
let (fprod, fcons) = buffer.try_split_framed().unwrap();
sourcepub fn try_release_framed(
&'a self,
prod: FrameProducer<'a, N>,
cons: FrameConsumer<'a, N>
) -> CoreResult<(), (FrameProducer<'a, N>, FrameConsumer<'a, N>)>
pub fn try_release_framed( &'a self, prod: FrameProducer<'a, N>, cons: FrameConsumer<'a, N> ) -> CoreResult<(), (FrameProducer<'a, N>, FrameConsumer<'a, N>)>
Attempt to release the Producer and Consumer in Framed mode
This re-initializes the buffer so it may be split in a different mode at a later time. There must be no read or write grants active, or an error will be returned.
The FrameProducer
and FrameConsumer
must be from THIS BBBuffer
, or an error
will be returned.
source§impl<const A: usize> BBBuffer<A>
impl<const A: usize> BBBuffer<A>
sourcepub const fn new() -> Self
pub const fn new() -> Self
Create a new constant inner portion of a BBBuffer
.
NOTE: This is only necessary to use when creating a BBBuffer
at static
scope, and is generally never used directly. This process is necessary to
work around current limitations in const fn
, and will be replaced in
the future.
use bbqueue::BBBuffer;
static BUF: BBBuffer<6> = BBBuffer::new();
fn main() {
let (prod, cons) = BUF.try_split().unwrap();
}