Skip to main content

BarrierGuard

Struct BarrierGuard 

Source
pub struct BarrierGuard<'vm> { /* private fields */ }
Expand description

RAII guard for the VPP worker thread barrier, returned by MainRef::barrier_sync

The barrier is released when this guard is dropped. Leaking the guard (e.g. via std::mem::forget) leaves the barrier held, which stalls workers but isn’t unsound.

Methods from Deref<Target = MainRef>§

Source

pub unsafe fn get_buffers<'a, 'me, 'buf: 'me, FeatureData, const N: usize>( &'me self, from_indices: &'a [u32], to: &mut ArrayVec<&'buf mut BufferRef<FeatureData>, N>, )

Get pointers to buffers for the given buffer indices, writing them into the provided to arrayvec.

This is similar to vlib_get_buffers in the C API.

Note that although it would be more idiomatic to return an ArrayVec directly, this method takes a mutable reference to an ArrayVec to avoid an unnecessary copy when returning.

§Safety
  • The caller must ensure that to has enough capacity to hold all the buffers corresponding to the indices in from_indices.
  • Each index in from_indices must be valid and the caller must have ownership of the buffer it corresponds to.
  • Each buffer’s current_config_index must be consistent with the FeatureData type. If they are not known (i.e. because the caller the node isn’t being executed in a feature arc), FeatureData should be a zero-sized type such as ().
  • The capacity of from_indices must be a multiple of 8 (note though that the length is allowed not to be). In other words, it must be valid to read multiples of 8 from the underlying memory (possibly returning uninitialised or stale data) without faulting.
Source

pub unsafe fn buffer_enqueue_to_next<N, V: VectorBufferIndex>( &self, node: &mut NodeRuntimeRef<N>, from: &[V], nexts: &[u16], )

Enqueues a slice of buffer indices to a next node

This corresponds to the VPP C function vlib_buffer_enqueue_to_next.

§Safety
  • The length of the from and next slices must match.
  • The next node must have a Vector type of u32 (or the C equivalent).
  • The next node must have a Scalar type of () (or the C equivalent).
  • The next node must have an Aux type of () (or the C equivalent).
  • vlib_buffer_func_main must have been filled in with valid function pointers (which will be done by VPP at initialisation time).
  • The buffer state, such as current_data and length must be set according to the preconditions of the next node.
  • Each entry in the from slice must be a valid index to a buffer.
  • Each entry in the nexts slice must be a valid next node index.
Source

pub fn alloc_buffer(&self) -> Result<BufferWithContext<'_>, BufferAllocError>

Allocate a single buffer

This corresponds to the VPP C API of vlib_alloc_buffers.

Source

pub fn buffer_default_data_size(&self) -> u32

Get the default data size for allocated buffers

This corresponds to the VPP C API vlib_buffer_get_default_data_size.

Source

pub fn as_ptr(&self) -> *mut vlib_main_t

Returns the raw pointer to the underlying vlib_main_t

Source

pub fn thread_index(&self) -> u16

Returns the 0-based thread index of this VPP main context

Source

pub fn barrier_sync(&self) -> BarrierGuard<'_>

Takes the VPP worker thread barrier, stopping all worker threads

Returns an RAII guard which releases the barrier when dropped and which dereferences to a BarrierHeldMainRef for use with APIs that require the barrier to be held.

The barrier is recursive in VPP, so it is fine to call this when the barrier is already held. If there are no worker threads then this is cheap.

The returned guard must not be held across an async await.

§Panics

Panics if not called on the VPP main thread.

Trait Implementations§

Source§

impl Deref for BarrierGuard<'_>

Source§

type Target = BarrierHeldMainRef

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl Drop for BarrierGuard<'_>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more

Auto Trait Implementations§

§

impl<'vm> !RefUnwindSafe for BarrierGuard<'vm>

§

impl<'vm> !Send for BarrierGuard<'vm>

§

impl<'vm> !Sync for BarrierGuard<'vm>

§

impl<'vm> !UnwindSafe for BarrierGuard<'vm>

§

impl<'vm> Freeze for BarrierGuard<'vm>

§

impl<'vm> Unpin for BarrierGuard<'vm>

§

impl<'vm> UnsafeUnpin for BarrierGuard<'vm>

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<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
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.