pub struct RwLock<T>(/* private fields */);Expand description
Reader-writer lock backed by a futex.
Drop-in replacement for parking_lot::RwLock<T>.
Non-fair: new readers are not blocked by waiting writers.
Additional methods beyond parking_lot:
is_locked_exclusive()— true when a write lock is heldget_n_waiters()— number of threads waiting (read + write)reader_count()— number of active readers
Implementations§
Source§impl<T> RwLock<T>
impl<T> RwLock<T>
Sourcepub fn read(&self) -> RwLockReadGuard<'_, T>
pub fn read(&self) -> RwLockReadGuard<'_, T>
Acquires a shared (read) lock, blocking until available.
Sourcepub fn write(&self) -> RwLockWriteGuard<'_, T>
pub fn write(&self) -> RwLockWriteGuard<'_, T>
Acquires an exclusive (write) lock, blocking until available.
Sourcepub fn try_read(&self) -> Option<RwLockReadGuard<'_, T>>
pub fn try_read(&self) -> Option<RwLockReadGuard<'_, T>>
Tries to acquire a shared lock without blocking.
Sourcepub fn try_write(&self) -> Option<RwLockWriteGuard<'_, T>>
pub fn try_write(&self) -> Option<RwLockWriteGuard<'_, T>>
Tries to acquire an exclusive lock without blocking.
Sourcepub fn try_read_for(&self, timeout: Duration) -> Option<RwLockReadGuard<'_, T>>
pub fn try_read_for(&self, timeout: Duration) -> Option<RwLockReadGuard<'_, T>>
Tries to acquire a shared lock within the given timeout.
Sourcepub fn try_write_for(
&self,
timeout: Duration,
) -> Option<RwLockWriteGuard<'_, T>>
pub fn try_write_for( &self, timeout: Duration, ) -> Option<RwLockWriteGuard<'_, T>>
Tries to acquire an exclusive lock within the given timeout.
Sourcepub fn is_locked(&self) -> bool
pub fn is_locked(&self) -> bool
Returns true if the lock is held by any reader or by the exclusive writer.
Sourcepub fn is_locked_exclusive(&self) -> bool
pub fn is_locked_exclusive(&self) -> bool
Returns true if the write (exclusive) lock is currently held.
Sourcepub fn get_n_waiters(&self) -> usize
pub fn get_n_waiters(&self) -> usize
Returns the total number of threads waiting to acquire this lock.
Sourcepub fn reader_count(&self) -> u32
pub fn reader_count(&self) -> u32
Returns the number of active readers.
Sourcepub fn raw(&self) -> &NoxuRawRwLock
pub fn raw(&self) -> &NoxuRawRwLock
Returns a reference to the raw NoxuRawRwLock.