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>§
Sourcepub 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>,
)
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
tohas enough capacity to hold all the buffers corresponding to the indices infrom_indices. - Each index in
from_indicesmust be valid and the caller must have ownership of the buffer it corresponds to. - Each buffer’s
current_config_indexmust be consistent with theFeatureDatatype. 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_indicesmust 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.
Sourcepub unsafe fn buffer_enqueue_to_next<N, V: VectorBufferIndex>(
&self,
node: &mut NodeRuntimeRef<N>,
from: &[V],
nexts: &[u16],
)
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
Vectortype ofu32(or the C equivalent). - The next node must have a
Scalartype of()(or the C equivalent). - The next node must have an
Auxtype of()(or the C equivalent). vlib_buffer_func_mainmust have been filled in with valid function pointers (which will be done by VPP at initialisation time).- The buffer state, such as
current_dataandlengthmust be set according to the preconditions of the next node. - Each entry in the
fromslice must be a valid index to a buffer. - Each entry in the
nextsslice must be a valid next node index.
Sourcepub fn alloc_buffer(&self) -> Result<BufferWithContext<'_>, BufferAllocError>
pub fn alloc_buffer(&self) -> Result<BufferWithContext<'_>, BufferAllocError>
Allocate a single buffer
This corresponds to the VPP C API of vlib_alloc_buffers.
Sourcepub fn buffer_default_data_size(&self) -> u32
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.
Sourcepub fn as_ptr(&self) -> *mut vlib_main_t
pub fn as_ptr(&self) -> *mut vlib_main_t
Returns the raw pointer to the underlying vlib_main_t
Sourcepub fn thread_index(&self) -> u16
pub fn thread_index(&self) -> u16
Returns the 0-based thread index of this VPP main context
Sourcepub fn barrier_sync(&self) -> BarrierGuard<'_>
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.