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
impl RwLockBuilder
Sourcepub fn with_sharing(self, sharing: RwLockSharing) -> Self
Available on neither DragonFly BSD nor NetBSD nor OpenBSD.
pub fn with_sharing(self, sharing: RwLockSharing) -> Self
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.
Sourcepub fn with_preference(self, preference: RwLockPreference) -> Self
Available on GNU and Linux only.
pub fn with_preference(self, preference: RwLockPreference) -> Self
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.
Sourcepub fn build_owned(self) -> OwnedRwLock
pub fn build_owned(self) -> OwnedRwLock
Constructs an OwnedRwLock.
Sourcepub unsafe fn build_borrowed<T>(
self,
raw: *mut RawRwLockAlloc,
memory: &T,
) -> BorrowedRwLock<'_>
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 ofraw(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.