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 theDefaultMutex
is aloom
mutex so thatmaitake-sync
primitives work nicely inloom
tests -
If the
std
feature is enabled, then theDefaultMutex
is astd::sync::Mutex
, so thatstd
users get an OS mutex rather than a spinlock. -
If the
critical-section
feature is enabled, then theDefaultMutex
is a spinlock that acquires a critical section once locked. This ensures that bare-metal users who have enabledcritical-section
get a mutex that disables IRQs when locked. -
Otherwise, the
DefaultMutex
is 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
ScopedRawMutex
trait, not theRawMutex
trait. In order to use methods or types that require aRawMutex
, you must provide your ownRawMutex
type. -
:warning: If the
critical-section
feature is enabled, you MUST provide acritical-section
implementation. See thecritical-section
documentation 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 theConstInit
trait 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, becauseloom
support can only be enabled by aRUSTFLAGS
cfg 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