FreeRTOScpp
Loading...
Searching...
No Matches
RecursiveMutex Class Reference

Recursive Mutex Wrapper. More...

#include <MutexCPP.h>

Inheritance diagram for RecursiveMutex:
Collaboration diagram for RecursiveMutex:

Public Member Functions

 RecursiveMutex (char const *name=nullptr)
 
 ~RecursiveMutex ()
 
bool give () override
 
bool take (TickType_t wait=portMAX_DELAY) override
 

Private Member Functions

 RecursiveMutex (RecursiveMutex const &)=delete
 We are not copyable.
 
void operator= (RecursiveMutex const &)=delete
 We are not assignable.
 

Private Attributes

SemaphoreHandle_t mutexHandle
 

Detailed Description

Recursive Mutex Wrapper.

A RecursiveMutex adds the ability to nest takes, so that if you have taken the RecursiveMutex and take it again, this works and requires you to give the RecursiveMutex back as many times as it was taken before it is released.

One very common application for this is for messages to the user on a console. Generally, you don't want pieces of a message interrupted by pieces of other messages, so message output routines use a mutex on the console port. These routines often use lower level routines that also want to make sure their output isn't interspersed, so each level takes the RecursiveMutex at their start and releases it at the end. Being a RecursiveMutex this works.

Example Usage:

RecursiveMutex mutex("MyMutex");
// In some other task
mutex.take();
...
// possible in a recursive call or call to lower level routine.
mutex.take();
...
mutex.give();
...
mutex.give();
Recursive Mutex Wrapper.
Definition MutexCPP.h:160

Constructor & Destructor Documentation

◆ RecursiveMutex() [1/2]

RecursiveMutex::RecursiveMutex ( char const * name = nullptr)
inline

◆ ~RecursiveMutex()

RecursiveMutex::~RecursiveMutex ( )
inline

◆ RecursiveMutex() [2/2]

RecursiveMutex::RecursiveMutex ( RecursiveMutex const & )
privatedelete

We are not copyable.

Member Function Documentation

◆ give()

bool RecursiveMutex::give ( )
inlineoverridevirtual

Implements Lockable.

◆ operator=()

void RecursiveMutex::operator= ( RecursiveMutex const & )
privatedelete

We are not assignable.

◆ take()

bool RecursiveMutex::take ( TickType_t wait = portMAX_DELAY)
inlineoverridevirtual

Implements Lockable.

Member Data Documentation

◆ mutexHandle

SemaphoreHandle_t RecursiveMutex::mutexHandle
private

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