pub struct AsyncRwLock<ST: SyncTypes, T: Send + Sync> { /* private fields */ }Expand description
A Read-Write Lock which can be waited asynchronously for.
The locking operations read() and write()
return Futures which can subsequently get polled to eventually obtain
the lock.
AsyncRwLock follows the common Read-Write Lock semantics: locking for
writes is mutually exclusive, with either locking type whereas any number of
read lockings can be granted at a time.
AsyncRwlock is not robust against threads “loosing interest”, e.g.
because the execution environment somehow abandoned them: any lock waiting
Future acquired from read() or write()
must either get polled to completion or dropped, otherwise it might block
other waiters for forever. Similar reasoning applies to the lock grant
guards themselves: AsyncRwLockReadGuard and AsyncRwLockWriteGuard
instances may always block other waiters, so it must be made sure that
progress is always driven forward for a lock holder until the respective
locking guard gets eventually dropped again.
Implementations§
Source§impl<ST: SyncTypes, T: Send + Sync> AsyncRwLock<ST, T>
impl<ST: SyncTypes, T: Send + Sync> AsyncRwLock<ST, T>
Sourcepub fn new(data: T) -> Self
pub fn new(data: T) -> Self
Instantiate a new AsyncRwLock
Note that the caller is supposed to move the returned AsyncSemaphore
into a SyncRcPtr – the other parts of
the API expect that.
§Arguments:
data- the data to wrap in the the lock.
Sourcepub fn read<'a, LP: 'a + SyncRcPtr<Self>, LR: 'a + SyncRcPtrRef<'a, Self, LP>>(
this: &LR,
) -> Result<AsyncRwLockReadFuture<ST, T, LP>, AsyncRwLockError>where
Self: 'a,
pub fn read<'a, LP: 'a + SyncRcPtr<Self>, LR: 'a + SyncRcPtrRef<'a, Self, LP>>(
this: &LR,
) -> Result<AsyncRwLockReadFuture<ST, T, LP>, AsyncRwLockError>where
Self: 'a,
Asynchronous, non-exclusive locking for read semantics.
Instantiate a AsyncRwLockReadFuture for taking the lock
asynchronously for read semantics.
The returned future will not become ready as long as an exlusive write
locking, i.e. an AsyncRwLockWriteGuard is active, or some waiter
for an exclusive write locking is ahead in line.
Note that the mere existence of a AsyncRwLockReadFuture
returned from this function may block other waiters – it must
always get either polled to completion or dropped again.
§Errors:
AsyncRwLockError::MemoryAllocationFailure- Memory allocation failure.
Sourcepub fn write<'a, LP: 'a + SyncRcPtr<Self>, LR: 'a + SyncRcPtrRef<'a, Self, LP>>(
this: &LR,
) -> Result<AsyncRwLockWriteFuture<ST, T, LP>, AsyncRwLockError>where
Self: 'a,
pub fn write<'a, LP: 'a + SyncRcPtr<Self>, LR: 'a + SyncRcPtrRef<'a, Self, LP>>(
this: &LR,
) -> Result<AsyncRwLockWriteFuture<ST, T, LP>, AsyncRwLockError>where
Self: 'a,
Asynchronous, exclusive locking for write semantics.
Instantiate a AsyncRwLockWriteFuture for taking the lock
asynchronously for write semantics.
The returned future will not become ready as long as some locking of any
type, i.e. an AsyncRwLockWriteGuard or AsyncRwLockReadGuard
is active, or some other waiter is ahead in line.
Note that the mere existence of a AsyncRwLockWriteFuture
returned from this function may block other waiters – it must
always get either polled to completion or dropped again.
§Errors:
AsyncRwLockError::MemoryAllocationFailure- Memory allocation failure.
Sourcepub fn try_read<'a, LP: 'a + SyncRcPtr<Self>, LR: 'a + SyncRcPtrRef<'a, Self, LP>>(
this: &LR,
) -> Option<AsyncRwLockReadGuard<ST, T, LP>>where
Self: 'a,
pub fn try_read<'a, LP: 'a + SyncRcPtr<Self>, LR: 'a + SyncRcPtrRef<'a, Self, LP>>(
this: &LR,
) -> Option<AsyncRwLockReadGuard<ST, T, LP>>where
Self: 'a,
Try to synchronously acquire lock non-exclusively for read semantics.
The operation will only succeed and return a AsyncRwLockReadGuard if
no exclusive locking is active or waited for to become available.
Otherwise None will get returned.
Sourcepub fn try_write<'a, LP: 'a + SyncRcPtr<Self>, LR: 'a + SyncRcPtrRef<'a, Self, LP>>(
this: &LR,
) -> Option<AsyncRwLockWriteGuard<ST, T, LP>>where
Self: 'a,
pub fn try_write<'a, LP: 'a + SyncRcPtr<Self>, LR: 'a + SyncRcPtrRef<'a, Self, LP>>(
this: &LR,
) -> Option<AsyncRwLockWriteGuard<ST, T, LP>>where
Self: 'a,
Try to synchronously acquire lock exclusively for write semantics.
The operation will only succeed and return a AsyncRwLockWriteGuard
if no locking is active or waited for to become available.
Otherwise None will get returned.