pub struct RwLock<L: Level, T> { /* private fields */ }
Implementations§
Source§impl<L: Level, T> RwLock<L, T>
A reader-writer lock
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.
Sourcepub fn into_inner(self) -> T
pub fn into_inner(self) -> T
Consumes this RwLock, returning the underlying data.
Sourcepub fn write<'a, LP: Lower<L> + 'a>(
&'a self,
lock_token: LockToken<'a, LP>,
) -> RwLockWriteGuard<'a, L, T>
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.
Sourcepub fn read<'a, LP: Lower<L> + 'a>(
&'a self,
lock_token: LockToken<'a, LP>,
) -> RwLockReadGuard<'a, L, T>
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.