FreeRTOS-Cpp
Loading...
Searching...
No Matches
Public Member Functions | List of all members
FreeRTOS::RecursiveMutex Class Reference

Class that encapsulates the functionality of a FreeRTOS recursive mutex. More...

#include <FreeRTOS/Mutex.hpp>

Inheritance diagram for FreeRTOS::RecursiveMutex:
Inheritance graph
[legend]
Collaboration diagram for FreeRTOS::RecursiveMutex:
Collaboration graph
[legend]

Public Member Functions

 RecursiveMutex ()
 Construct a new RecursiveMutex object by calling SemaphoreHandle_t xSemaphoreCreateRecursiveMutex( void )
 
 RecursiveMutex (const RecursiveMutex &)=delete
 
RecursiveMutexoperator= (const RecursiveMutex &)=delete
 
 RecursiveMutex (RecursiveMutex &&) noexcept=default
 
RecursiveMutexoperator= (RecursiveMutex &&) noexcept=default
 
- Public Member Functions inherited from FreeRTOS::RecursiveMutexBase
 RecursiveMutexBase (const RecursiveMutexBase &)=delete
 
RecursiveMutexBaseoperator= (const RecursiveMutexBase &)=delete
 
bool lock (const TickType_t ticksToWait=portMAX_DELAY) const
 Function that calls xSemaphoreTakeRecursive( SemaphoreHandle_t xMutex, TickType_t xTicksToWait )
 
bool unlock () const
 Function that calls xSemaphoreGiveRecursive( SemaphoreHandle_t xSemaphore )
 
- Public Member Functions inherited from FreeRTOS::MutexBase
 MutexBase (const MutexBase &)=delete
 
MutexBaseoperator= (const MutexBase &)=delete
 
bool isValid () const
 Function that checks if the underlying semaphore handle is not NULL. This should be used to ensure a semaphore has been created correctly.
 
bool lock (const TickType_t ticksToWait=portMAX_DELAY) const
 Function that calls xSemaphoreTake( SemaphoreHandle_t xSemaphore, TickType_t xTicksToWait )
 
bool lockFromISR (bool &higherPriorityTaskWoken) const
 Function that calls xSemaphoreTakeFromISR ( SemaphoreHandle_t xSemaphore, signed BaseType_t *pxHigherPriorityTaskWoken )
 
bool lockFromISR () const
 Function that calls xSemaphoreTakeFromISR ( SemaphoreHandle_t xSemaphore, signed BaseType_t *pxHigherPriorityTaskWoken )
 
bool unlock () const
 Function that calls xSemaphoreGive( SemaphoreHandle_t xSemaphore )
 

Additional Inherited Members

- Static Public Member Functions inherited from FreeRTOS::RecursiveMutexBase
static void * operator new (size_t, void *)
 
static void * operator new[] (size_t, void *)
 
static void * operator new (size_t)=delete
 
static void * operator new[] (size_t)=delete
 
- Static Public Member Functions inherited from FreeRTOS::MutexBase
static void * operator new (size_t)=delete
 
static void * operator new[] (size_t)=delete
 
static void * operator new (size_t, void *ptr)
 
static void * operator new[] (size_t, void *ptr)
 

Detailed Description

Class that encapsulates the functionality of a FreeRTOS recursive mutex.

Each recursive mutex require a small amount of RAM that is used to hold the recursive mutex's state. If a mutex is created using FreeRTOS::RecursiveMutex then the required RAM is automatically allocated from the FreeRTOS heap. If a recursive mutex is created using FreeRTOS::StaticRecursiveMutex then the RAM is provided by the application writer, which requires an additional parameter, but allows the RAM to be statically allocated at compile time. See the Static Vs Dynamic allocation page for more information.

Contrary to non-recursive mutexes, a task can lock a recursive mutex multiple times, and the recursive mutex will only be returned after the holding task has unlocked the mutex the same number of times it locked the mutex.

Like non-recursive mutexes, recursive mutexes implement a priority inheritance algorithm. The priority of a task that locks a mutex will be temporarily raised if another task of higher priority attempts to obtain the same mutex. The task that owns the mutex 'inherits' the priority of the task attempting to lock the same mutex. This means the mutex must always be unlocked otherwise the higher priority task will never be able to obtain the mutex, and the lower priority task will never 'disinherit' the priority.

Constructor & Destructor Documentation

◆ RecursiveMutex()

FreeRTOS::RecursiveMutex::RecursiveMutex ( )
inline

Construct a new RecursiveMutex object by calling SemaphoreHandle_t xSemaphoreCreateRecursiveMutex( void )

Mutex.hpp

See also
https://www.freertos.org/xSemaphoreCreateRecursiveMutex.html
Warning
The user should call isValid() on this object to verify that the recursive mutex was created successfully in case the memory required to create the queue could not be allocated.

Example Usage

#include <FreeRTOS/Mutex.hpp>
#include <FreeRTOS/Task.hpp>
class MyTask : public FreeRTOS::Task {
public:
void taskFunction() final;
};
void MyTask::taskFunction() {
// Create a recursive mutex.
if (mutex.isValid()) {
// The recursive mutex was created successfully and can now be used.
}
}
bool isValid() const
Function that checks if the underlying semaphore handle is not NULL. This should be used to ensure a ...
Definition Mutex.hpp:78
Class that encapsulates the functionality of a FreeRTOS recursive mutex.
Definition Mutex.hpp:358
Class that encapsulates the functionality of a FreeRTOS task.
Definition Task.hpp:1427

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