Boboter
Loading...
Searching...
No Matches
smart_mutex Class Reference

A RAII wrapper for mutexes which locks them at the beginning of its lifetime and releases them at the end of its lifetime (normally the scope in which the wrapper was created). More...

#include <smart_mutex.h>

Public Member Functions

 smart_mutex (SemaphoreHandle_t mutex)
 ~smart_mutex ()
 smart_mutex (const smart_mutex &)=delete
smart_mutexoperator= (const smart_mutex &)=delete

Detailed Description

A RAII wrapper for mutexes which locks them at the beginning of its lifetime and releases them at the end of its lifetime (normally the scope in which the wrapper was created).

To create a smart mutex, just do:

smart_mutex lock(mutex);
smart_mutex(SemaphoreHandle_t mutex)
Definition smart_mutex.h:27

Done! Now, the mutex will stay locked until the function finishes (until this object goes out of scope and its destructor is called) and then it will automatically unlock the mutex for you. Be careful that you don't lock the mutex and then call a function which again locks the mutex, which will cause the firmware to hang!!

Constructor & Destructor Documentation

◆ smart_mutex() [1/2]

smart_mutex::smart_mutex ( SemaphoreHandle_t mutex)
inlineexplicit

◆ ~smart_mutex()

smart_mutex::~smart_mutex ( )
inline

◆ smart_mutex() [2/2]

smart_mutex::smart_mutex ( const smart_mutex & )
delete

Member Function Documentation

◆ operator=()

smart_mutex & smart_mutex::operator= ( const smart_mutex & )
delete

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