Struct RwLock

Source
pub struct RwLock<L: Level, T> { /* private fields */ }

Implementations§

Source§

impl<L: Level, T> RwLock<L, T>

A reader-writer lock

This type of lock allows a number of readers or at most one writer at any point in time. The write portion of this lock typically allows modification of the underlying data (exclusive access) and the read portion of this lock typically allows for read-only access (shared access).

The type parameter T represents the data that this lock protects. It is required that T satisfies Send to be shared across threads and Sync to allow concurrent access through readers. The RAII guards returned from the locking methods implement Deref (and DerefMut for the write methods) to allow access to the contained of the lock.

Source

pub fn new(val: T) -> Self

Creates a new instance of an RwLock which is unlocked.

Source

pub fn into_inner(self) -> T

Consumes this RwLock, returning the underlying data.

Source

pub fn write<'a, LP: Lower<L> + 'a>( &'a self, lock_token: LockToken<'a, LP>, ) -> RwLockWriteGuard<'a, L, T>

Locks this RwLock with exclusive write access, blocking the current thread until it can be acquired. This function will not return while other writers or other readers currently have access to the lock. Returns an RAII guard which will drop the write access of this RwLock when dropped.

Source

pub fn read<'a, LP: Lower<L> + 'a>( &'a self, lock_token: LockToken<'a, LP>, ) -> RwLockReadGuard<'a, L, T>

Locks this RwLock with shared read access, blocking the current thread until it can be acquired.

The calling thread will be blocked until there are no more writers which hold the lock. There may be other readers currently inside the lock when this method returns.

Note that attempts to recursively acquire a read lock on a RwLock when the current thread already holds one may result in a deadlock.

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

Trait Implementations§

Source§

impl<L: Level, T: Default> Default for RwLock<L, T>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<L, T> !Freeze for RwLock<L, T>

§

impl<L, T> RefUnwindSafe for RwLock<L, T>
where L: RefUnwindSafe,

§

impl<L, T> Send for RwLock<L, T>
where T: Send, L: Send,

§

impl<L, T> Sync for RwLock<L, T>
where T: Send + Sync, L: Sync,

§

impl<L, T> Unpin for RwLock<L, T>
where L: Unpin, T: Unpin,

§

impl<L, T> UnwindSafe for RwLock<L, T>
where L: UnwindSafe,

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.