pub struct RawMutex(/* private fields */);Expand description
Mutex types and guards for mutual exclusion.
Low-level POSIX mutex: lock/unlock only, no guarded data and no RAII
guard. Most application code should use Mutex<T> instead; RawMutex
is for callers that need to manage the lock/unlock pairing themselves.
Implementations§
Trait Implementations§
Source§impl RawMutex for RawMutex
impl RawMutex for RawMutex
Source§fn is_null(&self) -> bool
fn is_null(&self) -> bool
Returns true if this mutex is never-initialized-or-already-deleted.
§Examples
use osal_rs::os::*;
let mut mutex = RawMutex::new().unwrap();
assert!(!mutex.is_null());
mutex.delete();
assert!(mutex.is_null());Source§fn lock(&self) -> OsalRsBool
fn lock(&self) -> OsalRsBool
Locks the mutex, blocking the calling thread until it becomes
available. Returns OsalRsBool::True on success.
§Examples
use osal_rs::os::*;
use osal_rs::utils::OsalRsBool;
let mutex = RawMutex::new().unwrap();
assert_eq!(mutex.lock(), OsalRsBool::True);
mutex.unlock();Source§fn lock_from_isr(&self) -> OsalRsBool
fn lock_from_isr(&self) -> OsalRsBool
ISR-safe variant of RawMutex::lock. POSIX has no interrupt
context of its own, so this never blocks (trylock instead of
lock); it returns OsalRsBool::False if the mutex is already
held rather than waiting for it.
§Examples
use osal_rs::os::*;
use osal_rs::utils::OsalRsBool;
let mutex = RawMutex::new().unwrap();
assert_eq!(mutex.lock_from_isr(), OsalRsBool::True);
mutex.unlock_from_isr();Source§fn unlock(&self) -> OsalRsBool
fn unlock(&self) -> OsalRsBool
Unlocks the mutex. Must be called by the thread that currently holds the lock.
§Examples
use osal_rs::os::*;
use osal_rs::utils::OsalRsBool;
let mutex = RawMutex::new().unwrap();
mutex.lock();
assert_eq!(mutex.unlock(), OsalRsBool::True);Source§fn unlock_from_isr(&self) -> OsalRsBool
fn unlock_from_isr(&self) -> OsalRsBool
ISR-safe variant of RawMutex::unlock; identical on POSIX, since
unlocking never blocks.