class CriticalMutex
Defined at line 214 of file ../../zircon/kernel/include/kernel/mutex.h
CriticalMutex is a mutex variant that uses a thread timeslice extension to
disable preemption for a limited time during the critical section.
Acquiring a CriticalMutex sets a timeslice extension that's cleared when the
mutex is released or the extension expires, whichever comes first.
This variant is useful to avoid a form of thrash where a thread holding a
mutex is preempted by another thread that subsequently blocks while trying to
acquire the already held mutex. CriticalMutex is designed to mitigate this
type of thrash by preventing the holder from being preempted, up to some
maximum amount of time. By limiting maximum amount of time the holder is
non-preemptible, we can limit the degree to which other, logically higher
priority tasks are delayed from executing.
Good candidates for CriticalMutex are global or widely shared locks that
typically, but not necessarily always, have very short critical sections
(tens of microseconds or less) and high contention under load.
CriticalMutex differs from SpinLock in the following ways:
* Threads contending a CriticalMutex will block after the spin interval is
exceeded, avoiding extended monopolization of multiple CPUs.
* Threads may block while holding a CriticalMutex, simplifying maintaining
invariants in slow paths.
* Interrupts may remain enabled while holding a CriticalMutex, avoiding
undesirable IRQ latency.
Public Methods
void CriticalMutex ()
Defined at line 216 of file ../../zircon/kernel/include/kernel/mutex.h
void ~CriticalMutex ()
Defined at line 217 of file ../../zircon/kernel/include/kernel/mutex.h
void CriticalMutex (const fxt::InternedString & name_stringref)
Defined at line 218 of file ../../zircon/kernel/include/kernel/mutex.h
void CriticalMutex (const CriticalMutex & )
Defined at line 220 of file ../../zircon/kernel/include/kernel/mutex.h
CriticalMutex & operator= (const CriticalMutex & )
Defined at line 221 of file ../../zircon/kernel/include/kernel/mutex.h
void CriticalMutex (CriticalMutex && )
Defined at line 222 of file ../../zircon/kernel/include/kernel/mutex.h
CriticalMutex & operator= (CriticalMutex && )
Defined at line 223 of file ../../zircon/kernel/include/kernel/mutex.h
ShouldClear Acquire (zx_duration_t spin_max_duration)
Defined at line 229 of file ../../zircon/kernel/include/kernel/mutex.h
void Release (ShouldClear should_clear)
Release the mutex. Must be held by the current thread. The |should_clear| parameter is the
return value of the matching |Acquire| call.
Defined at line 239 of file ../../zircon/kernel/include/kernel/mutex.h
bool IsHeld ()
See |Mutex::IsHeld|.
Defined at line 248 of file ../../zircon/kernel/include/kernel/mutex.h
void AssertHeld ()
See |Mutex::AssertHeld|.
Defined at line 251 of file ../../zircon/kernel/include/kernel/mutex.h
bool IsContested ()
See |Mutex::IsContested|.
Defined at line 254 of file ../../zircon/kernel/include/kernel/mutex.h
void SetLockClassId (lockdep::LockClassId lcid)
We inherited privately from Mutex, which hides the SetLockClassId method
from lockdep. Explicitly pass the call it makes to SetLockClassId to the
underlying implementation so we get named locked when we are collecting
lock contention trace data.
Defined at line 260 of file ../../zircon/kernel/include/kernel/mutex.h
Enumerations
enum ShouldClear
| Name | Value |
|---|---|
| No | false |
| Yes | true |
Acquire the mutex. Returns whether or not a time slice extension was set, and must be
subsequently cleared on Release. More simply, the return value must be passed into the Release
method.
Defined at line 228 of file ../../zircon/kernel/include/kernel/mutex.h