Struct shared_mutex::SharedMutex
[−]
[src]
pub struct SharedMutex<T: ?Sized> { // some fields omitted }
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
.
Methods
impl<T> SharedMutex<T>
[src]
fn new(value: T) -> Self
Create a new SharedMutex protecting the given value.
fn into_inner(self) -> LockResult<T>
Extract the data from the lock and destroy the lock.
Safe since it requires ownership of the lock.
impl<T: ?Sized> SharedMutex<T>
[src]
fn write(&self) -> LockResult<SharedMutexWriteGuard<T>>
Acquire an exclusive Write lock on the data.
fn read(&self) -> LockResult<SharedMutexReadGuard<T>>
Acquire a shared Read lock on the data.
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
.
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
.
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.