Pigweed
|
#include <mutex.h>
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 |
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.
embed:rst:leading-asterisk * .. warning:: * * In order to support global statically constructed Mutexes, the user * and/or backend MUST ensure that any initialization required in your * environment is done prior to the creation and/or initialization of the * native synchronization primitives (e.g. kernel initialization). *
void pw::sync::Mutex::lock | ( | ) |
Locks the mutex, blocking indefinitely. Failures are fatal.
PRECONDITION: The lock isn't already held by this thread. Recursive locking is undefined behavior.
|
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.
PRECONDITION: The lock isn't already held by this thread. Recursive locking is undefined behavior.
void pw::sync::Mutex::unlock | ( | ) |
Unlocks the mutex. Failures are fatal.
PRECONDITION: The mutex is held by this thread.