pub struct MainRef(/* private fields */);Expand description
Reference to VPP per-thread main library context
This is a safe wrapper around vlib_main_t, providing access to its fields.
A &mut MainRef is equivalent to a vlib_main_t * in C (a *mut vlib_main_t in Rust).
See also BarrierHeldMainRef for a variant that indicates the caller holds the
main thread barrier.
Implementations§
Source§impl MainRef
impl 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
feature_arc_indexandcurrent_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: Node, V: VectorBufferIndex>(
&self,
node: &mut NodeRuntimeRef<N>,
from: &[V],
nexts: &[u16],
)
pub unsafe fn buffer_enqueue_to_next<N: Node, 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.
Source§impl MainRef
impl MainRef
Sourcepub unsafe fn from_ptr_mut<'a>(ptr: *mut vlib_main_t) -> &'a mut Self
pub unsafe fn from_ptr_mut<'a>(ptr: *mut vlib_main_t) -> &'a mut Self
Creates a &mut MainRef directly from a pointer
§Safety
- The pointer must be valid and a properly initialised
vlib_main_tfor the thread. - The pointer must stay valid and the contents must not be mutated for the duration of the lifetime of the returned object.
- The
vlib_main_tmust have been created by VPP at startup and not manually by the caller, as many datastructures size the memory they allocate by the number of threads at startup and are subsequently indexed by thread index.
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