pub trait RelockMutexGuard {
    type MutexRef: Clone + Send;
    type JustGuard;
    type LockFuture: Future + Send
    where
        <Self::LockFuture as Future>::Output == Self::JustGuard
; fn unlock_for_relock(self) -> Self::MutexRef; fn lock(r: Self::MutexRef) -> Self::LockFuture; }
Expand description

Lock guards that can be unlocked and relocked

Purpose

Condvar::wait_baton and wait need to unlock and then relock the mutex. So, they need to be able to recover &Mutex from the guard.

Regaining the mutex ref

If the lock in use doesn’t support this (e.g., at the time of writing, std::sync::Mutex, it is usually possible to implement this trait on a tuple struct of guard and lock reference (and, therefore, pass that tuple struct to Condvar::wait.

Provided implementations and support

Implementations are provided for a handful of common MutexGuard types. Contributions of more (with the appropriate optional dpendencies in Cargo.toml are welcome.

The RelockMutexGuard! macro can save much boilerplate in the common cases.

Semantics

async-condvar-fair assumes that RelockMutexGuard impl’s are sensible. If they aren’t, malfunctions including deadlocks or livelocks or panics are possible. But memory safety won’t be compromised.

Required Associated Types

The reference to the mutex, recovered after unlocking.

The actual guard type.

Where Self (the argument to wait_baton or wait contains both a guard and a separate mutex reference, it is typically most convvenient for the wait futures to produce just the mutex guard.

That is what this type is.

The type of the relock future.

Required Methods

Unlock the mutex and return a reference tt.

Relock the mutex, given a reference.

Poisoning (as found in std::sync::Mutedx) will have to propagate poisoning as panics, or or ignore it, since notify_one insists that someone must go and acquire the mutex which they can’t if that always fails due to poisoning.

Implementations on Foreign Types

Implementors