Struct maitake_sync::blocking::DefaultMutex  
source · 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 a [std::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§
source§impl DefaultMutex
 
impl DefaultMutex
sourcepub const fn new() -> Self
 
pub const fn new() -> Self
Returns a new DefaultMutex.
See the type-level documentation for details on how to use a DefaultMutex.
Trait Implementations§
source§impl Debug for DefaultMutex
 
impl Debug for DefaultMutex
source§impl Default for DefaultMutex
 
impl Default for DefaultMutex
source§impl ScopedRawMutex for DefaultMutex
 
impl ScopedRawMutex for DefaultMutex
source§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