Skip to main content

PriorityMutex

Struct PriorityMutex 

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

Source

pub const fn new(data: T) -> Self

Create a new mutex

Source

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.

Source

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.

Trait Implementations§

Source§

impl<P, T, const FIFO: bool, const LOWEST_FIRST: bool> Debug for PriorityMutex<P, T, FIFO, LOWEST_FIRST>
where T: Debug, P: Default + Ord,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<P: Default + Ord, T: Default, const FIFO: bool, const LOWEST_FIRST: bool> Default for PriorityMutex<P, T, FIFO, LOWEST_FIRST>

Source§

fn default() -> PriorityMutex<P, T, FIFO, LOWEST_FIRST>

Returns the “default value” for a type. Read more
Source§

impl<P: Ord, T, const FIFO: bool, const LOWEST_FIRST: bool> From<T> for PriorityMutex<P, T, FIFO, LOWEST_FIRST>

Source§

fn from(value: T) -> Self

Converts to this type from the input type.
Source§

impl<P: Ord + Sync, T: Sync, const FIFO: bool, const LOWEST_FIRST: bool> Sync for PriorityMutex<P, T, FIFO, LOWEST_FIRST>

Auto Trait Implementations§

§

impl<P, T, const FIFO: bool = false, const LOWEST_FIRST: bool = false> !Freeze for PriorityMutex<P, T, FIFO, LOWEST_FIRST>

§

impl<P, T, const FIFO: bool = false, const LOWEST_FIRST: bool = false> !RefUnwindSafe for PriorityMutex<P, T, FIFO, LOWEST_FIRST>

§

impl<P, T, const FIFO: bool, const LOWEST_FIRST: bool> Send for PriorityMutex<P, T, FIFO, LOWEST_FIRST>
where T: Send, P: Send,

§

impl<P, T, const FIFO: bool, const LOWEST_FIRST: bool> Unpin for PriorityMutex<P, T, FIFO, LOWEST_FIRST>
where T: Unpin,

§

impl<P, T, const FIFO: bool, const LOWEST_FIRST: bool> UnsafeUnpin for PriorityMutex<P, T, FIFO, LOWEST_FIRST>
where T: UnsafeUnpin,

§

impl<P, T, const FIFO: bool, const LOWEST_FIRST: bool> UnwindSafe for PriorityMutex<P, T, FIFO, LOWEST_FIRST>
where 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<!> for T

Source§

fn from(t: !) -> T

Converts to this type from the input type.
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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.