pub struct RawSharedMutex { /* private fields */ }
Expand description
A raw lock providing both shared read locks and exclusive write locks.
Used as a raw building block for other synchronization primitives. Most
users should just use SharedMutex<T>
, which takes care of tieing the lock
to some data.
Implementations§
Sourcepub fn new() -> RawSharedMutex
pub fn new() -> RawSharedMutex
Create a new RawSharedMutex
Sourcepub fn is(&self, other: &Self) -> bool
pub fn is(&self, other: &Self) -> bool
Checks if this mutex and the other are the same mutex.
If is
returns true, the two references point to the same
mutex, and they may be used interchangeably.
Sourcepub fn read(&self)
pub fn read(&self)
Acquire a shared read lock.
Blocks until a read lock can be acquired. The lock can be released
by calling unlock_read
.
Sourcepub fn try_read(&self) -> bool
pub fn try_read(&self) -> bool
Attempt to acquire a shared read lock without blocking.
Returns true if we succeeded and false if acquiring a read lock would require blocking.
Sourcepub fn write(&self)
pub fn write(&self)
Acquire an exclusive write lock.
Blocks until the write lock can be acquired. The lock can be released
by calling unlock_write
.
Sourcepub fn try_write(&self) -> bool
pub fn try_write(&self) -> bool
Attempt to acquire an exclusive write lock without blocking.
Returns true if we succeeded and false if acquiring the write lock would require blocking.
Sourcepub fn unlock_read(&self)
pub fn unlock_read(&self)
Unlock a previously acquired read lock.
Behavior is unspecified (but not undefined) if unlock_read
is called
without a previous accompanying read
.
Sourcepub fn unlock_write(&self)
pub fn unlock_write(&self)
Unlock a previously acquired write lock.
Behavior is unspecified (but not undefined) if unlock_write
is called
without a previous accompanying write
.
Sourcepub fn wait_from_read_to_write(&self, cond: &Condvar)
pub fn wait_from_read_to_write(&self, cond: &Condvar)
Wait on the given condition variable, resuming with a write lock.
Behavior is unspecified if there was no previous accompanying read
.
Sourcepub fn wait_from_read_to_read(&self, cond: &Condvar)
pub fn wait_from_read_to_read(&self, cond: &Condvar)
Wait on the given condition variable, resuming with another read lock.
Behavior is unspecified if there was no previous accompanying read
.
Sourcepub fn wait_from_write_to_read(&self, cond: &Condvar)
pub fn wait_from_write_to_read(&self, cond: &Condvar)
Wait on the given condition variable, resuming with a read lock.
Behavior is unspecified if there was no previous accompanying write
.
Sourcepub fn wait_from_write_to_write(&self, cond: &Condvar)
pub fn wait_from_write_to_write(&self, cond: &Condvar)
Wait on the given condition variable, resuming with another write lock.
Behavior is unspecified if there was no previous accompanying write
.