pub type StaticRecursiveMutex<System, T> = GenericRecursiveMutex<Hunk<System, MaybeUninit<MutexInner<T>>>, StaticMutex<System>>;
Available on crate feature sync only.
Expand description

A defined (statically created) GenericRecursiveMutex.

Example

use core::cell::Cell;
use r3::{kernel::StaticTask, sync::StaticRecursiveMutex};

struct Objects {
    mutex: StaticRecursiveMutex<System, Cell<i32>>,
}

const fn configure_app<C>(cfg: &mut Cfg<C>) -> Objects
where
    C: ~const traits::CfgTask<System = System> +
       ~const traits::CfgMutex,
{
    StaticTask::define()
        .start(task1_body)
        .priority(2)
        .active(true)
        .finish(cfg);

    let mutex = StaticRecursiveMutex::define()
        .init(|| Cell::new(1))
        .finish(cfg);

    Objects { mutex }
}

fn task1_body() {
    let guard = COTTAGE.mutex.lock().unwrap();
    assert_eq!(guard.get(), 1);
    guard.set(2);

    {
        // Recursive lock is allowed
        let guard2 = COTTAGE.mutex.lock().unwrap();
        assert_eq!(guard2.get(), 2);
        guard2.set(3);
    }

    assert_eq!(guard.get(), 3);
}

Implementations§

source§

impl<System, T: 'static> StaticRecursiveMutex<System, T>where System: KernelMutex + KernelStatic,

source

pub const fn define() -> Definer<System, DefaultSource<MutexInner<T>>>

Construct a Definer to define a mutex in a configuration function.