10#include <freertos/FreeRTOS.h>
64template <
typename struct_type>
67 static constexpr const char* TAG =
"protected_struct";
70 mutable SemaphoreHandle_t mutex;
76 if (parent.mutex ==
nullptr) {
77 parent.mutex = xSemaphoreCreateMutex();
79 if (parent.mutex !=
nullptr) {
80 xSemaphoreTake(parent.mutex, portMAX_DELAY);
83 ~proxy() { xSemaphoreGive(parent.mutex); }
89 return const_cast<struct_type*
>(&parent.data);
96 operator struct_type&()
const {
97 return *
const_cast<struct_type*
>(&parent.data);
104 if (mutex !=
nullptr) {
105 vSemaphoreDelete(mutex);
proxy operator->() const
Overload of the get value from dereferenced pointer operator to make it possible to get a value using...
Definition protected_struct.h:118
protected_struct(const protected_struct &)=delete
protected_struct & operator=(const protected_struct &)=delete
protected_struct()
Definition protected_struct.h:102
~protected_struct()
Definition protected_struct.h:103
proxy operator*() const
Overload of the dereference operator to make it possible to pass the whole struct to something.
Definition protected_struct.h:128