#[repr(C, align(16))]pub struct RWLock<T: ?Sized> { /* private fields */ }Expand description
An exclusive access lock around the given data
Implementations§
Source§impl<T: ?Sized> RWLock<T>
impl<T: ?Sized> RWLock<T>
Sourcepub fn try_write(&self) -> Option<WriteLockGuard<'_, T>>
pub fn try_write(&self) -> Option<WriteLockGuard<'_, T>>
Try to provide a Writelock for mutual exclusive access. Returns None if the lock fails
or Some(WriteLockGuard). The actual data, the WriteLockGuard wraps could be conviniently accessed by
dereferencing it.
Sourcepub fn write(&self) -> WriteLockGuard<'_, T>
pub fn write(&self) -> WriteLockGuard<'_, T>
Provide a WriteLock for mutual exclusive access. This blocks until the data could be successfully locked. This also implies that there is no concurrent ReadLockGuard existing. The locked data will be returned as WriteLockGuard. Simply derefrencing this allows access to the contained data value.
Sourcepub fn try_read(&self) -> Option<ReadLockGuard<'_, T>>
pub fn try_read(&self) -> Option<ReadLockGuard<'_, T>>
Provide a ReadLock to the wrapped data. This call blocks until the recource is available. There can be as many concurrent ReadLockGuards being handed out if there is no WriteLockGuard to the same resource already existing.
Sourcepub fn read(&self) -> ReadLockGuard<'_, T>
pub fn read(&self) -> ReadLockGuard<'_, T>
Provide a ReadLock to the wrapped data. This call blocks until the recource is available. There can be as many concurrent ReadLockGuards being handed out if there is no WriteLockGuard to the same resource already existing.
Sourcepub unsafe fn as_ref_unchecked(&self) -> &T
pub unsafe fn as_ref_unchecked(&self) -> &T
Provide an immutable borrow to the data secured by the RWLock.
§Safety
This is only safe if it is guarantied that there is exactly only one call to this function or any other accessor of the RWLock until the returned borrow goes out of scope.
Sourcepub fn into_inner(self) -> Twhere
T: Sized,
pub fn into_inner(self) -> Twhere
T: Sized,
Consume the Mutex and return the inner value
Trait Implementations§
impl<T: ?Sized + Send> Sync for RWLock<T>
The RWLock is always Sync, to make it Send as well it need to be wrapped into an Arc.