Skip to main content

AsyncRwLock

Struct AsyncRwLock 

Source
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>

Source

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.
Source

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:
Source

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:
Source

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.

Source

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.

Auto Trait Implementations§

§

impl<ST, T> !Freeze for AsyncRwLock<ST, T>

§

impl<ST, T> !RefUnwindSafe for AsyncRwLock<ST, T>

§

impl<ST, T> Send for AsyncRwLock<ST, T>
where AsyncSemaphore<ST, T>: Send,

§

impl<ST, T> Sync for AsyncRwLock<ST, T>
where AsyncSemaphore<ST, T>: Sync,

§

impl<ST, T> Unpin for AsyncRwLock<ST, T>
where AsyncSemaphore<ST, T>: Unpin,

§

impl<ST, T> UnsafeUnpin for AsyncRwLock<ST, T>

§

impl<ST, T> UnwindSafe for AsyncRwLock<ST, T>
where AsyncSemaphore<ST, T>: UnwindSafe,

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 = !

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

fn try_from(value: U) -> Result<T, !>

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.