Pigweed
Loading...
Searching...
No Matches
pw::sync::Mutex Class Reference

#include <mutex.h>

Public Types

using native_handle_type = backend::NativeMutexHandle
 

Public Member Functions

 Mutex (const Mutex &)=delete
 
 Mutex (Mutex &&)=delete
 
Mutexoperator= (const Mutex &)=delete
 
Mutexoperator= (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
 

Detailed Description

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).
*  

Member Function Documentation

◆ lock()

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.

◆ native_type()

backend::NativeMutex & pw::sync::Mutex::native_type ( )
inlineprotected

Expose the NativeMutex directly to derived classes (TimedMutex) in case implementations use different types for backend::NativeMutex and native_handle().

◆ try_lock()

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.

◆ unlock()

void pw::sync::Mutex::unlock ( )

Unlocks the mutex. Failures are fatal.

PRECONDITION: The mutex is held by this thread.


The documentation for this class was generated from the following file: