Struct abi::bbqueue_ipc::BBBuffer

source ·
#[repr(C)]
pub struct BBBuffer { buf: AtomicPtr<u8>, buf_len: AtomicUsize, write: AtomicUsize, read: AtomicUsize, last: AtomicUsize, reserve: AtomicUsize, read_in_progress: AtomicBool, write_in_progress: AtomicBool, }
Expand description

A backing structure for a BBQueue. Can be used to create either a BBQueue or a split Producer/Consumer pair

Fields§

§buf: AtomicPtr<u8>§buf_len: AtomicUsize§write: AtomicUsize

Where the next byte will be written

§read: AtomicUsize

Where the next byte will be read from

§last: AtomicUsize

Used in the inverted case to mark the end of the readable streak. Otherwise will == sizeof::<self.buf>(). Writer is responsible for placing this at the correct place when entering an inverted condition, and Reader is responsible for moving it back to sizeof::<self.buf>() when exiting the inverted condition

§reserve: AtomicUsize

Used by the Writer to remember what bytes are currently allowed to be written to, but are not yet ready to be read from

§read_in_progress: AtomicBool

Is there an active read grant?

§write_in_progress: AtomicBool

Is there an active write grant?

Implementations§

source§

impl<'a> BBBuffer

source

pub unsafe fn initialize(&'a self, buf_start: *mut u8, buf_len: usize)

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

pub unsafe fn take_producer(me: *mut Self) -> Producer<'static>

source

pub unsafe fn take_consumer(me: *mut Self) -> Consumer<'static>

source

pub unsafe fn take_framed_producer(me: *mut Self) -> FrameProducer<'static>

source

pub unsafe fn take_framed_consumer(me: *mut Self) -> FrameConsumer<'static>

source§

impl BBBuffer

source

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

Trait Implementations§

source§

impl Debug for BBBuffer

source§

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

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

impl Sync for BBBuffer

Auto Trait Implementations§

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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 Twhere 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 Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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.