Struct DefaultMutex
pub struct DefaultMutex(/* private fields */);Expand description
Default, best-effort ScopedRawMutex implementation.
This is the default Lock type parameter for the Mutex
type, and for the async synchronization primitives that use the blocking
Mutex. This type makes a best-effort attempt to Do The Right Thing based
on the currently enabled feature flags. In particular, here’s what we
currently give you:
-
If
cfg(loom)is enabled, then theDefaultMutexis aloommutex so thatmaitake-syncprimitives work nicely inloomtests -
If the
stdfeature is enabled, then theDefaultMutexis astd::sync::Mutex, so thatstdusers get an OS mutex rather than a spinlock. -
If the
critical-sectionfeature is enabled, then theDefaultMutexis a spinlock that acquires a critical section once locked. This ensures that bare-metal users who have enabledcritical-sectionget a mutex that disables IRQs when locked. -
Otherwise, the
DefaultMutexis aSpinlock. This is the default behavior and will at least work on all platforms, but may not be the most efficient, and may not be IRQ-safe.
§Notes
-
Regardless of feature flags, this type implements the
ScopedRawMutextrait, not theRawMutextrait. In order to use methods or types that require aRawMutex, you must provide your ownRawMutextype. -
:warning: If the
critical-sectionfeature is enabled, you MUST provide acritical-sectionimplementation. See thecritical-sectiondocumentation for details on how to select an implementation. If you don’t provide an implementation, you’ll get a linker error when compiling your code. -
This type has a
const fn new()constructor and implements theConstInittrait except whencfg(loom)is enabled.Loom users are probably already aware that
loom’s simulated types cannot be const initialized, as they must bind to the current test iteration when constructed. This is not a non-additive feature flag, becauseloomsupport can only be enabled by aRUSTFLAGScfg set by the top-level build, and not by a dependency.s
Implementations§
§impl DefaultMutex
impl DefaultMutex
pub const fn new() -> DefaultMutex
pub const fn new() -> DefaultMutex
Returns a new DefaultMutex.
See the type-level documentation for details on how to use a DefaultMutex.
Trait Implementations§
§impl ConstInit for DefaultMutex
impl ConstInit for DefaultMutex
§const INIT: DefaultMutex
const INIT: DefaultMutex
§impl Debug for DefaultMutex
impl Debug for DefaultMutex
§impl Default for DefaultMutex
impl Default for DefaultMutex
§fn default() -> DefaultMutex
fn default() -> DefaultMutex
§impl ScopedRawMutex for DefaultMutex
impl ScopedRawMutex for DefaultMutex
§fn with_lock<R>(&self, f: impl FnOnce() -> R) -> R
fn with_lock<R>(&self, f: impl FnOnce() -> R) -> R
ScopedRawMutex, calling f() after the lock has been acquired, and releasing
the lock after the completion of f(). Read more§fn try_with_lock<R>(&self, f: impl FnOnce() -> R) -> Option<R>
fn try_with_lock<R>(&self, f: impl FnOnce() -> R) -> Option<R>
ScopedRawMutex, calling f() after the lock has been acquired, and releasing
the lock after the completion of f(). Read more