StaticMutex

Struct StaticMutex 

Source
pub struct StaticMutex<T: ?Sized> { /* private fields */ }
Expand description

A statically-allocated mutex for protecting shared data.

Similar to Mutex<T> but designed to be allocated at compile time as a static variable. Requires explicit initialization before use.

§Examples

use osal_rs::os::StaticMutex;
 
static mut COUNTER_MUTEX: Option<StaticMutex<u32>> = None;
 
// During initialization:
unsafe {
    COUNTER_MUTEX = Some(StaticMutex::new(0).unwrap());
}

Implementations§

Source§

impl<T> StaticMutex<T>

Source

pub fn new(data: T) -> Result<Self>

Creates a new static mutex protecting the given data.

§Parameters
  • data - The initial value to protect
§Returns
  • Ok(StaticMutex) - Successfully created
  • Err(Error::OutOfMemory) - Failed to allocate mutex resources
§Examples
let mutex = StaticMutex::new(42).unwrap();
Source§

impl<T> StaticMutex<T>

Source

pub fn init(&mut self) -> Result<()>

Initializes the mutex.

Note: The mutex is already initialized in the constructor. This method is provided for API compatibility.

§Returns

Always returns Ok(())

Trait Implementations§

Source§

impl<T> StaticMutex<T> for StaticMutex<T>

Source§

fn lock(&self) -> Result<StaticMutexGuard<'_, T>>

Acquires the lock and returns a guard.

Blocks until the lock is available.

Source§

fn lock_from_isr(&self) -> Result<StaticMutexGuardFromIsr<'_, T>>

Acquires the lock from ISR context and returns an ISR guard.

Non-blocking version for interrupt service routines.

Source§

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

Returns a mutable reference to the underlying data.

Safe because it requires exclusive mutable access to the mutex.

Source§

type Guard<'a> = StaticMutexGuard<'a, T> where Self: 'a, T: 'a

Guard type returned by lock(), providing RAII-style mutex access. Read more
Source§

type GuardFromIsr<'a> = StaticMutexGuardFromIsr<'a, T> where Self: 'a, T: 'a

Guard type returned by lock_from_isr(), for ISR-context mutex access. Read more

Auto Trait Implementations§

§

impl<T> !Freeze for StaticMutex<T>

§

impl<T> !RefUnwindSafe for StaticMutex<T>

§

impl<T> Send for StaticMutex<T>
where T: Send + ?Sized,

§

impl<T> !Sync for StaticMutex<T>

§

impl<T> Unpin for StaticMutex<T>
where T: Unpin + ?Sized,

§

impl<T> UnwindSafe for StaticMutex<T>
where T: UnwindSafe + ?Sized,

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.

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>,

Source§

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>,

Source§

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.