Skip to main content

RwLockBuilder

Struct RwLockBuilder 

Source
pub struct RwLockBuilder { /* private fields */ }
Expand description

The main entrypoint for creating rwlocks. Internally, it initialises a pthread_rwlockattr_t and decorates it with the attributes passed in from the Self::with_* methods, returning the rwlock after a call to build_owned or build_borrowed.

If, instead, you already have a RawRwLockAlloc somewhere in memory and just need to interpret it as a BorrowedRwLock, use BorrowedRwLock::from_raw.

Implementations§

Source§

impl RwLockBuilder

Source

pub fn new() -> Self

Creates a default RwLockBuilder.

Source

pub fn with_sharing(self, sharing: RwLockSharing) -> Self

Available on neither DragonFly BSD nor NetBSD nor OpenBSD.

Sets the process-shared attribute of the to-be constructed rwlock. See pthread_rwlockattr_setpshared for more information.

Not available on DragonFly, NetBSD or OpenBSD, none of which implements process sharing.

Source

pub fn with_preference(self, preference: RwLockPreference) -> Self

Available on GNU and Linux only.

Sets who wins when readers and writers contend for the to-be constructed rwlock.

This is pthread_rwlockattr_setkind_np, a GNU extension rather than part of POSIX. bionic exports a variant of it with its own differently numbered constants, and FreeBSD declares it in pthread.h without any library defining it, so this crate offers it on glibc alone.

Source

pub fn build_owned(self) -> OwnedRwLock

Constructs an OwnedRwLock.

Source

pub unsafe fn build_borrowed<T>( self, raw: *mut RawRwLockAlloc, memory: &T, ) -> BorrowedRwLock<'_>

Constructs a BorrowedRwLock at a given location.

  • raw: A pointer to uninitialised data.

  • memory: A reference to a RAII object whose lifetime determines the validity of raw (e.g. a struct that manages a memory map).

§Safety

The caller must guarantee that raw is correctly aligned, points to at least RawRwLockAlloc::SIZE writable bytes, and is not already in use by an initialised rwlock.

Trait Implementations§

Source§

impl Default for RwLockBuilder

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Drop for RwLockBuilder

Source§

fn drop(&mut self)

Releases the attribute object. The rwlocks built from it are unaffected: pthread_rwlock_init copies whatever it needs out of the attributes rather than holding onto them.

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

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.