pub struct PriorityMutex<P: Ord, T, const FIFO: bool = false, const LOWEST_FIRST: bool = false> { /* private fields */ }Expand description
A mutex that distributes access by priority as opposed to just fifo / whoever gets it first. If fifo isn’t set, the current behavior is lifo - however this is may not always be the case. Having fifo = false means it doesn’t matter the order of items with the same priority (instead, they will be queued in whichever order is fastest - currently, lifo)
If this is non-desirable, the type alias FIFOPriorityMutex can be used or the const param can FIFO be set manually to true.
By default, a highor P is higher priorrity, but this can be reversed via setting the LOWEST_FIRST const arg to true (or by using the LowestFirstPriorityMutex alias type.
Implementations§
Source§impl<P: Ord, T, const FIFO: bool, const LOWEST_FIRST: bool> PriorityMutex<P, T, FIFO, LOWEST_FIRST>
impl<P: Ord, T, const FIFO: bool, const LOWEST_FIRST: bool> PriorityMutex<P, T, FIFO, LOWEST_FIRST>
Sourcepub fn try_lock(
&self,
priority: P,
) -> Result<PriorityMutexGuard<'_, P, T, FIFO, LOWEST_FIRST>, TryLockError>
pub fn try_lock( &self, priority: P, ) -> Result<PriorityMutexGuard<'_, P, T, FIFO, LOWEST_FIRST>, TryLockError>
Try to acquire the lock without blocking or requesting eviction of the current holder.
Priority will be stored in guard; higher priority requesters will try to evict the returned
guard if the evict flag is enabled.
Sourcepub async fn lock(
&self,
priority: P,
) -> PriorityMutexGuard<'_, P, T, FIFO, LOWEST_FIRST>
pub async fn lock( &self, priority: P, ) -> PriorityMutexGuard<'_, P, T, FIFO, LOWEST_FIRST>
Acquire exclusive access to the locked resource, waiting until after higher priority requesters acquire and release the lock.
If the evict feature is enabled, this will also notify the current holder to request it
to release the lock if the current holder is lower priority.
Cancel safety: this function is cancel safe.