28#ifndef FREERTOS_SEMAPHORE_HPP
29#define FREERTOS_SEMAPHORE_HPP
57 static void*
operator new(size_t) =
delete;
58 static void*
operator new[](size_t) =
delete;
60 static void*
operator new(size_t,
void* ptr) {
64 static void*
operator new[](size_t,
void* ptr) {
97 return uxSemaphoreGetCount(
handle);
125 inline bool take(
const TickType_t ticksToWait = portMAX_DELAY)
const {
126 return (xSemaphoreTake(
handle, ticksToWait) == pdTRUE);
159 BaseType_t taskWoken = pdFALSE;
160 const bool result = (xSemaphoreTakeFromISR(
handle, &taskWoken) == pdTRUE);
161 if (taskWoken == pdTRUE) {
162 higherPriorityTaskWoken =
true;
178 return (xSemaphoreTakeFromISR(
handle, NULL) == pdTRUE);
203 return (xSemaphoreGive(
handle) == pdTRUE);
230 BaseType_t taskWoken = pdFALSE;
231 const bool result = (xSemaphoreGiveFromISR(
handle, &taskWoken) == pdTRUE);
232 if (taskWoken == pdTRUE) {
233 higherPriorityTaskWoken =
true;
249 return (xSemaphoreGiveFromISR(
handle, NULL) == pdTRUE);
267 vSemaphoreDelete(this->
handle);
280#if (configSUPPORT_DYNAMIC_ALLOCATION == 1)
341 this->
handle = xSemaphoreCreateBinary();
405 const UBaseType_t initialCount = 0) {
406 this->
handle = xSemaphoreCreateCounting(maxCount, initialCount);
419#if (configSUPPORT_STATIC_ALLOCATION == 1)
481 this->handle = xSemaphoreCreateBinaryStatic(&staticBinarySemaphore);
492 StaticSemaphore_t staticBinarySemaphore;
518 const UBaseType_t initialCount = 0) {
519 this->handle = xSemaphoreCreateCountingStatic(maxCount, initialCount,
520 &staticCountingSemaphore);
532 StaticSemaphore_t staticCountingSemaphore;
Class that encapsulates the functionality of a FreeRTOS binary semaphore.
Definition Semaphore.hpp:323
BinarySemaphore()
Construct a new BinarySemaphore object by calling SemaphoreHandle_t xSemaphoreCreateBinary( void )
Definition Semaphore.hpp:340
Class that encapsulates the functionality of a FreeRTOS counting semaphore.
Definition Semaphore.hpp:386
CountingSemaphore(const UBaseType_t maxCount, const UBaseType_t initialCount=0)
Construct a new CountingSemaphore by calling SemaphoreHandle_t xSemaphoreCreateCounting( UBaseType_t ...
Definition Semaphore.hpp:404
Base class that provides the standard semaphore interface to FreeRTOS::BinarySemaphore,...
Definition Semaphore.hpp:47
bool takeFromISR() const
Function that calls xSemaphoreTakeFromISR( SemaphoreHandle_t xSemaphore, signed BaseType_t *pxHigherP...
Definition Semaphore.hpp:177
bool take(const TickType_t ticksToWait=portMAX_DELAY) const
Function that calls xSemaphoreTake( SemaphoreHandle_t xSemaphore, TickType_t xTicksToWait )
Definition Semaphore.hpp:125
bool give() const
Function that calls xSemaphoreGive( SemaphoreHandle_t xSemaphore )
Definition Semaphore.hpp:202
SemaphoreHandle_t handle
Handle used to refer to the semaphore when using the FreeRTOS interface.
Definition Semaphore.hpp:277
bool takeFromISR(bool &higherPriorityTaskWoken) const
Function that calls xSemaphoreTakeFromISR( SemaphoreHandle_t xSemaphore, signed BaseType_t *pxHigherP...
Definition Semaphore.hpp:158
UBaseType_t getCount() const
Function that calls UBaseType_t uxSemaphoreGetCount( SemaphoreHandle_t xSemaphore )
Definition Semaphore.hpp:96
bool isValid() const
Function that checks if the underlying semaphore handle is not NULL. This should be used to ensure a ...
Definition Semaphore.hpp:77
bool giveFromISR() const
Function that calls xSemaphoreGiveFromISR( SemaphoreHandle_t xSemaphore, signed BaseType_t *pxHigherP...
Definition Semaphore.hpp:248
~SemaphoreBase()
Destroy the SemaphoreBase object by calling void vSemaphoreDelete( SemaphoreHandle_t xSemaphore )
Definition Semaphore.hpp:266
bool giveFromISR(bool &higherPriorityTaskWoken) const
Function that calls xSemaphoreGiveFromISR( SemaphoreHandle_t xSemaphore, signed BaseType_t *pxHigherP...
Definition Semaphore.hpp:229
Class that encapsulates the functionality of a FreeRTOS binary semaphore.
Definition Semaphore.hpp:462
StaticBinarySemaphore()
Construct a new StaticBinarySemaphore object by calling SemaphoreHandle_t xSemaphoreCreateBinaryStati...
Definition Semaphore.hpp:480
Definition Semaphore.hpp:495
StaticCountingSemaphore(const UBaseType_t maxCount, const UBaseType_t initialCount=0)
Construct a new StaticCountingSemaphore object by calling SemaphoreHandle_t xSemaphoreCreateCountingS...
Definition Semaphore.hpp:517