CDC Badge OS
Firmware for the CDC Badge v1.0 hardware security key
Loading...
Searching...
No Matches
cdc::core::MutexGuard Class Reference

RAII wrapper for a FreeRTOS semaphore / mutex. More...

#include <Raii.h>

Public Member Functions

 MutexGuard (SemaphoreHandle_t sem) noexcept
 Take sem blocking until acquired.
 ~MutexGuard () noexcept
 MutexGuard (const MutexGuard &)=delete
MutexGuardoperator= (const MutexGuard &)=delete
 MutexGuard (MutexGuard &&other) noexcept
bool locked () const noexcept
 True if the semaphore is currently held.
void release () noexcept
 Release the semaphore before destruction. Idempotent.

Static Public Member Functions

static MutexGuard tryLock (SemaphoreHandle_t sem, TickType_t ticks) noexcept

Detailed Description

RAII wrapper for a FreeRTOS semaphore / mutex.

Default constructor takes the semaphore with portMAX_DELAY; destructor gives it back. Use the static tryLock factory for non-blocking acquisition. Non-copyable.

Not safe to call from ISR context (use xSemaphoreTakeFromISR directly there).

Definition at line 181 of file Raii.h.

Constructor & Destructor Documentation

◆ MutexGuard() [1/3]

cdc::core::MutexGuard::MutexGuard ( SemaphoreHandle_t sem)
inlineexplicitnoexcept

Take sem blocking until acquired.

Definition at line 184 of file Raii.h.

Referenced by MutexGuard(), MutexGuard(), operator=(), and tryLock().

◆ ~MutexGuard()

cdc::core::MutexGuard::~MutexGuard ( )
inlinenoexcept

Definition at line 189 of file Raii.h.

◆ MutexGuard() [2/3]

cdc::core::MutexGuard::MutexGuard ( const MutexGuard & )
delete

References MutexGuard().

◆ MutexGuard() [3/3]

cdc::core::MutexGuard::MutexGuard ( MutexGuard && other)
inlinenoexcept

Definition at line 197 of file Raii.h.

References MutexGuard().

Member Function Documentation

◆ locked()

bool cdc::core::MutexGuard::locked ( ) const
inlinenoexcept

True if the semaphore is currently held.

Definition at line 205 of file Raii.h.

◆ operator=()

MutexGuard & cdc::core::MutexGuard::operator= ( const MutexGuard & )
delete

References MutexGuard().

◆ release()

void cdc::core::MutexGuard::release ( )
inlinenoexcept

Release the semaphore before destruction. Idempotent.

Definition at line 208 of file Raii.h.

◆ tryLock()

MutexGuard cdc::core::MutexGuard::tryLock ( SemaphoreHandle_t sem,
TickType_t ticks )
inlinestaticnoexcept

Try to acquire sem for up to ticks ticks. The returned guard is "locked" only if acquisition succeeded; check via .locked().

Definition at line 218 of file Raii.h.

References MutexGuard().


The documentation for this class was generated from the following file:
  • components/cdc_core/include/cdc_core/Raii.h