26 template<
typename... Args>
27 Mutex(Args && ... args) : value(std::forward<Args>(args)...)
29 mutex = xSemaphoreCreateMutexStatic(&buffer);
32 std::optional<GuardT> lock(TickType_t timeout)
34 if (xSemaphoreTake(mutex, timeout))
36 return std::optional{GuardT{
this}};
38 return std::optional<GuardT>{};
43 while (!xSemaphoreTake(mutex, portMAX_DELAY)) { }
49 return xSemaphoreGive(mutex) == pdTRUE;
52 T & unsafeGetUnderlying()
58 SemaphoreHandle_t mutex;
59 StaticSemaphore_t buffer;
69 Guard(MutexT * mutex_) : mutex(mutex_) { }
70 Guard(
const Guard &) =
delete;
71 Guard & operator=(
const Guard &) =
delete;
72 Guard(Guard &&) =
default;
73 Guard & operator=(Guard &&) =
default;
76 bool success = mutex->unlock();
82 return &mutex->unsafeGetUnderlying();
85 const T * operator->()
const
87 return &mutex->unsafeGetUnderlying();