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 the DefaultMutex is a loom mutex so that maitake-sync primitives work nicely in loom tests

  • If the std feature is enabled, then the DefaultMutex is a std::sync::Mutex, so that std users get an OS mutex rather than a spinlock.

  • If the critical-section feature is enabled, then the DefaultMutex is a spinlock that acquires a critical section once locked. This ensures that bare-metal users who have enabled critical-section get a mutex that disables IRQs when locked.

  • Otherwise, the DefaultMutex is a Spinlock. 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 the RawMutex trait. In order to use methods or types that require a RawMutex, you must provide your own RawMutex type.

  • :warning: If the critical-section feature is enabled, you MUST provide a critical-section implementation. See the critical-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 the ConstInit trait except when cfg(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, because loom support can only be enabled by a RUSTFLAGS cfg set by the top-level build, and not by a dependency.s

Implementations§

source§

impl DefaultMutex

source

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 ConstInit for DefaultMutex

source§

const INIT: Self = _

Create a new instance. Read more
source§

impl Debug for DefaultMutex

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Default for DefaultMutex

source§

fn default() -> Self

Returns the “default value” for a type. Read more
source§

impl ScopedRawMutex for DefaultMutex

source§

fn with_lock<R>(&self, f: impl FnOnce() -> R) -> R

Lock this ScopedRawMutex, calling f() after the lock has been acquired, and releasing the lock after the completion of f(). Read more
source§

fn try_with_lock<R>(&self, f: impl FnOnce() -> R) -> Option<R>

Lock this ScopedRawMutex, calling f() after the lock has been acquired, and releasing the lock after the completion of f(). Read more
source§

fn is_locked(&self) -> bool

Is this mutex currently locked?

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more