pub struct OwnedRwLock { /* private fields */ }Expand description
A rwlock that owns its underlying raw rwlock. Dropping the OwnedRwLock destroys it, provided
nobody still holds it: destroying a held rwlock is undefined, so a guard that was leaked rather
than dropped leaks the pthread object with it. If you want to construct a rwlock in shared
memory for IPC, use a BorrowedRwLock instead.
Because the allocation belongs to this object and nothing outside the process can reach it, the locking methods are safe.
Implementations§
Source§impl OwnedRwLock
impl OwnedRwLock
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates a rwlock with the default attributes. Use RwLockBuilder to set any of the
others.
Sourcepub fn read(&self) -> Result<ReadGuard<'_>, RwLockError>
pub fn read(&self) -> Result<ReadGuard<'_>, RwLockError>
Acquires a read lock, blocking until it is available. Any number of readers can hold the lock at the same time.
§Errors
See RwLockError
Sourcepub fn try_read(&self) -> Result<Option<ReadGuard<'_>>, RwLockError>
pub fn try_read(&self) -> Result<Option<ReadGuard<'_>>, RwLockError>
Attempts to acquire a read lock without blocking. A lock that a writer is holding, or that
a writer is waiting for on a writer-preferring rwlock, is reported as Ok(None).
§Errors
See RwLockError
Sourcepub fn read_for(
&self,
timeout: Duration,
) -> Result<Option<ReadGuard<'_>>, RwLockError>
Available on non-Apple only.
pub fn read_for( &self, timeout: Duration, ) -> Result<Option<ReadGuard<'_>>, RwLockError>
Acquires a read lock, blocking until it is available or timeout elapses. A lock that
could not be acquired in time is reported as Ok(None).
The timeout is resolved against CLOCK_REALTIME, which is the clock
pthread_rwlock_timedrdlock
is defined in terms of. Stepping the system clock therefore moves the deadline.
Not available on Apple platforms, which do not implement the timed rwlock functions.
§Errors
See RwLockError
Sourcepub fn write(&self) -> Result<WriteGuard<'_>, RwLockError>
pub fn write(&self) -> Result<WriteGuard<'_>, RwLockError>
Acquires the write lock, blocking until it is available. Nobody else holds the lock while the returned guard is alive.
§Errors
See RwLockError
Sourcepub fn try_write(&self) -> Result<Option<WriteGuard<'_>>, RwLockError>
pub fn try_write(&self) -> Result<Option<WriteGuard<'_>>, RwLockError>
Attempts to acquire the write lock without blocking. A lock anyone else holds, reader or
writer, is reported as Ok(None).
§Errors
See RwLockError
Sourcepub fn write_for(
&self,
timeout: Duration,
) -> Result<Option<WriteGuard<'_>>, RwLockError>
Available on non-Apple only.
pub fn write_for( &self, timeout: Duration, ) -> Result<Option<WriteGuard<'_>>, RwLockError>
Acquires the write lock, blocking until it is available or timeout elapses. A lock that
could not be acquired in time is reported as Ok(None).
The timeout is resolved against CLOCK_REALTIME, as for read_for.
Not available on Apple platforms, which do not implement the timed rwlock functions.
§Errors
See RwLockError
Sourcepub fn as_raw_rwlock(&self) -> *mut pthread_rwlock_t
pub fn as_raw_rwlock(&self) -> *mut pthread_rwlock_t
Returns a pointer to the underlying pthread_rwlock_t.
The pointer stays valid until this OwnedRwLock is dropped.
Trait Implementations§
Source§impl Debug for OwnedRwLock
impl Debug for OwnedRwLock
Source§impl Default for OwnedRwLock
impl Default for OwnedRwLock
Source§impl Drop for OwnedRwLock
impl Drop for OwnedRwLock
Source§fn drop(&mut self)
fn drop(&mut self)
Calls pthread_rwlock_destroy
on the underlying rwlock if nobody holds it.