pub struct SharedMutex<T: ?Sized> { /* private fields */ }
Expand description
A lock providing both shared read locks and exclusive write locks.
Similar to std::sync::RwLock
, except that its guards (SharedMutexReadGuard
and
SharedMutexWriteGuard
) can wait on std::sync::Condvar
s, which is very
useful for implementing efficient concurrent programs.
Another difference from std::sync::RwLock
is that the guard types are Send
.
Implementations§
Sourcepub fn into_inner(self) -> LockResult<T>
pub fn into_inner(self) -> LockResult<T>
Extract the data from the lock and destroy the lock.
Safe since it requires ownership of the lock.
Sourcepub fn write(&self) -> LockResult<SharedMutexWriteGuard<'_, T>>
pub fn write(&self) -> LockResult<SharedMutexWriteGuard<'_, T>>
Acquire an exclusive Write lock on the data.
Sourcepub fn read(&self) -> LockResult<SharedMutexReadGuard<'_, T>>
pub fn read(&self) -> LockResult<SharedMutexReadGuard<'_, T>>
Acquire a shared Read lock on the data.
Sourcepub fn try_read(&self) -> TryLockResult<SharedMutexReadGuard<'_, T>>
pub fn try_read(&self) -> TryLockResult<SharedMutexReadGuard<'_, T>>
Attempt to acquire a shared Read lock on the data.
If acquiring the lock would block, returns TryLockError::WouldBlock
.
Sourcepub fn try_write(&self) -> TryLockResult<SharedMutexWriteGuard<'_, T>>
pub fn try_write(&self) -> TryLockResult<SharedMutexWriteGuard<'_, T>>
Attempt to acquire an exclusive Write lock on the data.
If acquiring the lock would block, returns TryLockError::WouldBlock
.
Sourcepub fn get_mut(&mut self) -> LockResult<&mut T>
pub fn get_mut(&mut self) -> LockResult<&mut T>
Get a mutable reference to the data without locking.
Safe since it requires exclusive access to the lock itself.