EtcPal  0.4.1
ETC Platform Abstraction Layer (EtcPal)
View other versions:
RecursiveMutex Class Reference

Overview

A wrapper class for the EtcPal recursive mutex type.

WARNING: Recursive mutexes are rarely necessary for new code. They are often used to retrofit thread-safety into existing code. They can hide nasty bugs. Use regular etcpal::Mutex whenever possible.

Note: The etcpal::RecursiveMutex functions are not normally used directly - prefer usage of the RAII type etcpal::RecursiveMutexGuard to manage locking and unlocking of an etcpal::RecursiveMutex.

See etcpal::Mutex for example usage.

See recursive_mutex (Recursive Mutexes) for more information on the recursive mutex time.

Public Member Functions

 RecursiveMutex ()
 Create a new recursive mutex.
 
 ~RecursiveMutex ()
 Destroy the recursive mutex.
 
 RecursiveMutex (const RecursiveMutex &other)=delete
 
RecursiveMutexoperator= (const RecursiveMutex &other)=delete
 
 RecursiveMutex (RecursiveMutex &&other)=delete
 
RecursiveMutexoperator= (RecursiveMutex &&other)=delete
 
bool Lock ()
 Lock the mutex. More...
 
bool TryLock (int timeout_ms=0)
 Attempt to lock the recursive mutex. More...
 
void Unlock ()
 Unlock the recursive mutex. More...
 
etcpal_recursive_mutex_tget ()
 Get a reference to the underlying etcpal_recursive_mutex_t type.
 

Member Function Documentation

◆ Lock()

bool Lock ( )
inline

Lock the mutex.

Returns
The result of etcpal_recursive_mutex_lock() on the underlying mutex.

◆ TryLock()

bool TryLock ( int  timeout_ms = 0)
inline

Attempt to lock the recursive mutex.

Returns when either the mutex is acquired or the timeout expires. NOTE: Timeout values other than 0 or ETCPAL_WAIT_FOREVER are typically only honored on real-time platforms. See the table in recursive_mutex (Recursive Mutexes) for more information. On platforms where timeouts are not honored, passing 0 for timeout_ms executes a poll for the mutex returning immediately, while any other value executes the equivalent of Lock().

Parameters
timeout_msHow long to wait to acquire the mutex, in milliseconds. Default is to poll and return immediately.
Returns
The result of etcpal_recursive_mutex_timed_lock() on the underlying mutex.

◆ Unlock()

void Unlock ( )
inline

Unlock the recursive mutex.

See etcpal_recursive_mutex_unlock().


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