embedded_mutex

Crates.ioembedded_mutex
lib.rsembedded_mutex
version0.1.0
created_at2025-08-21 23:37:53.348051+00
updated_at2025-08-21 23:37:53.348051+00
descriptionA minimal, no_std, non-blocking mutex for embedded Rust.
homepage
repository
max_upload_size
id1805616
size4,537
(WebAppEnjoyer)

documentation

README

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();
        }
    }
}
Commit count: 0

cargo fmt