The Mutex
is a synchronization primitive that can be used to protect shared data from being simultaneously accessed by multiple threads. It offers exclusive, non-recursive ownership semantics where priority inheritance is used to solve the classic priority-inversion problem. This is thread safe, but NOT IRQ safe.
Public Types | |
using | native_handle_type = backend::NativeMutexHandle |
Public Member Functions | |
Mutex (const Mutex &)=delete | |
Mutex (Mutex &&)=delete | |
Mutex & | operator= (const Mutex &)=delete |
Mutex & | operator= (Mutex &&)=delete |
void | lock () |
bool | try_lock () |
void | unlock () |
native_handle_type | native_handle () |
Protected Member Functions | |
backend::NativeMutex & | native_type () |
const backend::NativeMutex & | native_type () const |
void pw::sync::Mutex::lock | ( | ) |
Locks the mutex, blocking indefinitely. Failures are fatal.
|
inlineprotected |
Expose the NativeMutex
directly to derived classes (TimedMutex
) in case implementations use different types for backend::NativeMutex
and native_handle()
.
bool pw::sync::Mutex::try_lock | ( | ) |
Attempts to lock the mutex in a non-blocking manner. Returns true if the mutex was successfully acquired.
void pw::sync::Mutex::unlock | ( | ) |
Unlocks the mutex. Failures are fatal.