embedded_mutex 0.1.0

A minimal, no_std, non-blocking mutex for embedded Rust.
Documentation
  • Coverage
  • 20%
    1 out of 5 items documented0 out of 4 items with examples
  • Size
  • Source code size: 4.02 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 704.68 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Links
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • WebAppEnjoyer

embedded_mutex

A minimal, no_std-friendly, non-blocking mutex for embedded Rust.

EmbeddedMutex<T> provides a very lightweight mutual exclusion primitive for no_std environments where you want to avoid blocking and have full control over when the lock is released.

Safety notice: This is a low-level primitive. The try_get method is unsafe because it hands out a &mut T without tying its lifetime to a guard. You must manually release the lock by calling return_mutex once you are done.


Features

  • #![no_std] compatible
  • Non-blocking try_get acquisition
  • Minimal atomic-based implementation
  • Works in bare-metal and embedded contexts
  • Zero allocations

Example

#![no_std]
use embedded_mutex::EmbeddedMutex;

static MY_MUTEX: EmbeddedMutex<u32> = EmbeddedMutex::new(0);

fn example_usage() {
    unsafe {
        if let Some(data) = MY_MUTEX.try_get() {
            *data += 1;
            // IMPORTANT: release the mutex when done
            MY_MUTEX.return_mutex();
        }
    }
}