Skip to main content

BarrierRwLock

Struct BarrierRwLock 

Source
pub struct BarrierRwLock<T: ?Sized> { /* private fields */ }
Expand description

A read/write lock using VPP’s barrier to provide exclusion between threads

VPP implements a barrier in the main thread which blocks all worker threads from running. The BarrierRwLock is an abstraction around this which allows a writer in the VPP main thread whilst the barrier is held and readers in either VPP workers or the VPP main thread.

Taking read or write “locks” are guaranteed to never block - blocking instead occurs in the VPP main and worker threads when the VPP barrier is taken.

Implementations§

Source§

impl<T> BarrierRwLock<T>

Source

pub const fn new(t: T) -> Self

Create a new barrier-backed read/write lock.

Source§

impl<T: ?Sized> BarrierRwLock<T>

Source

pub fn read(&self, vm: &MainRef) -> BarrierRwLockReadGuard<'_, T>

Locks this BarrierRwLock with shared read access.

Returns an RAII guard which will release this thread’s shared access once it is dropped.

§Panics

Panics if a write lock has already been taken by this thread and not dropped.

Source

pub fn write(&self, vm: &BarrierHeldMainRef) -> BarrierRwLockWriteGuard<'_, T>

Locks this BarrierRwLock with write access.

This is used on the VPP main thread in contexts where the VPP barrier is held.

Returns an RAII guard which will release this thread’s access once it is dropped.

§Panics

Panics if a read or another write lock has already been taken by this thread and not dropped.

Source

pub fn get_mut(&mut self) -> &mut T

Get a mutable reference to the contained data without locking.

This call borrows the BarrierRwLock mutably (at compile-time) which guarantees that we possess the only reference.

Source

pub const fn data_ptr(&self) -> *mut T

Returns a raw pointer to the underlying data.

The returned pointer is always non-null and properly aligned, but it is the user’s responsibility to ensure that any reads and writes through it are properly synchronized to avoid data races, and that it is not read or written through after the lock is dropped.

Source§

impl<T> BarrierRwLock<T>

Source

pub fn into_inner(self) -> T

Consume the lock and return the underlying data.

Trait Implementations§

Source§

impl<T: Default> Default for BarrierRwLock<T>

Source§

fn default() -> BarrierRwLock<T>

Creates a new BarrierRwLock<T>, with the Default value for T.

Source§

impl<T: ?Sized + Send> Send for BarrierRwLock<T>

Source§

impl<T: ?Sized + Send + Sync> Sync for BarrierRwLock<T>

Auto Trait Implementations§

§

impl<T> !Freeze for BarrierRwLock<T>

§

impl<T> !RefUnwindSafe for BarrierRwLock<T>

§

impl<T> Unpin for BarrierRwLock<T>
where T: Unpin + ?Sized,

§

impl<T> UnsafeUnpin for BarrierRwLock<T>
where T: UnsafeUnpin + ?Sized,

§

impl<T> UnwindSafe for BarrierRwLock<T>
where T: UnwindSafe + ?Sized,

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<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

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 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.