2 releases (1 stable)

1.0.0 Jan 31, 2025
0.1.0 Jul 22, 2024

#120 in Concurrency

Download history 33/week @ 2024-11-11 50/week @ 2024-11-18 38/week @ 2024-11-25 78/week @ 2024-12-02 147/week @ 2024-12-09 332/week @ 2024-12-16 64/week @ 2024-12-23 132/week @ 2025-01-13 156/week @ 2025-01-20 161/week @ 2025-01-27 233/week @ 2025-02-03

682 downloads per month

MIT/Apache

40KB
472 lines

mutex

When a mutex and a closure love each other very much.

Crates.io Version Crates.io License docs.rs GitHub Release CI

Mutex implementations using mutex-traits.

Versioning, and which crate to use?

The mutex-traits crate should be used by library crates that want to be generic over different ways of exclusive access.

The mutex crate should be used by applications that need to select which implementation is appropriate for their use case. The mutex crate also re-exports the mutex-traits crate for convenience, so applications only need to pull in one direct dependency.

While both crates are >= 1.0, it should be expected that it is more likely that mutex crate will make breaking changes someday. The hope is that mutex-traits NEVER releases a 2.0 version, which means that even if there are 1.x, 2.x, 3.x, etc. versions of the mutex crate, they all can be used interchangably since they implement the 1.x mutex-traits interfaces.

If you are a library crate, consider ONLY relying on the mutex-traits crate directly, and put any use of the mutex crate behind a feature flag or in the dev-dependencies section.

Crate Feature Flags

The following feature flags enable implementations of mutex_traits::ScopedRawMutex and mutex_traits::RawMutex:

  • impl-critical-section (default: true): Enables implementations of ScopedRawMutex for the critical-section crate.
  • impl-lock_api-0_4 (default: false): Enables a wrapper type implementing RawMutex for types implementing the lock_api crate's RawMutex trait.
  • impl-unsafe-cortex-m-single-core (default: false): Enables implementations of ScopedRawMutex which may only be used on single-core Cortex-M devices.

In addition, this crate exposes the following additional feature flags, for functionality other than implementations of ScopedRawMutex/RawMutex:

  • std (default: false): Enables features that require the Rust standard library.

    When this feature flag is disabled, this crate compiles with #![no_std] and does not require liballoc.

  • fmt (default: false): Enables implementations of core::fmt::Debug and core::fmt::Display for types provided by this crate.

    These formatting trait impls are feature-flagged so that they can be disabled by embedded projects and other use-cases where minimizing binary size is important.

Provenance

Portions of this code are forked from the embassy-sync crate.

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Dependencies

~46KB