Skip to main content

Module mutex

Module mutex 

Source
Expand description

Priority-inheritance mutex for the preemptive tier.

Classic priority inversion: a low-priority task holds a resource; a high-priority task blocks waiting for it; a medium-priority task (uninvolved with the resource) preempts the low-priority holder and runs indefinitely, indirectly blocking the high-priority task for far longer than the critical section itself would ever take.

Priority inheritance fixes this: while a higher-priority task is blocked on a mutex, the current holder’s effective priority is boosted to match, so it can’t be preempted by anything the waiter itself couldn’t preempt. The boost is undone on unlock — but see [B11]: with nested mutexes, unlocking one must recompute the boost from the remaining held mutexes rather than blindly restoring the base priority.

Structs§

PriorityMutex
A mutex that applies priority inheritance to its holder while higher-priority tasks are waiting on it.
PriorityMutexGuard
RAII guard returned by PriorityMutex::lock. On drop: releases the mutex, recomputes the holder’s effective priority from its remaining held mutexes ([B11] — nested inheritance), wakes waiters, and requests a reschedule.

Enums§

LockError
Error returned by PriorityMutex::lock_timeout.

Functions§

poison_mutex
Mark a type-erased PriorityMutex as poisoned and wake its waiters so they observe the poison (called by the fault-isolation path, plan.md §3.4).