Skip to main content

OwnedRwLock

Struct OwnedRwLock 

Source
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

Source

pub fn new() -> Self

Creates a rwlock with the default attributes. Use RwLockBuilder to set any of the others.

Source

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

Source

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

Source

pub fn read_for( &self, timeout: Duration, ) -> Result<Option<ReadGuard<'_>>, RwLockError>

Available on non-Apple only.

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

Source

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

Source

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

Source

pub fn write_for( &self, timeout: Duration, ) -> Result<Option<WriteGuard<'_>>, RwLockError>

Available on non-Apple only.

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

Source

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

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for OwnedRwLock

Source§

fn default() -> Self

Equivalent to RwLockBuilder::new().build_owned().

Source§

impl Drop for OwnedRwLock

Source§

fn drop(&mut self)

Calls pthread_rwlock_destroy on the underlying rwlock if nobody holds it.

Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more
Source§

impl Send for OwnedRwLock

Source§

impl Sync for OwnedRwLock

Source§

impl Unpin for OwnedRwLock

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.