fsfw/src/fsfw/osal/freertos/CountingSemaphore.h

37 lines
1.2 KiB
C
Raw Normal View History

2020-09-18 13:15:14 +02:00
#ifndef FRAMEWORK_OSAL_FREERTOS_COUNTINGSEMAPHORE_H_
#define FRAMEWORK_OSAL_FREERTOS_COUNTINGSEMAPHORE_H_
2020-12-14 11:17:22 +01:00
#include "BinarySemaphore.h"
2020-09-18 13:15:14 +02:00
/**
* @brief Counting semaphores, which can be acquire more than once.
* @details
* See: https://www.freertos.org/CreateCounting.html
* API of counting semaphores is almost identical to binary semaphores,
* so we just inherit from binary semaphore and provide the respective
* constructors.
*/
2022-02-02 10:29:30 +01:00
class CountingSemaphore : public BinarySemaphore {
public:
CountingSemaphore(const uint8_t maxCount, uint8_t initCount);
//! @brief Copy ctor, disabled
CountingSemaphore(const CountingSemaphore &) = delete;
//! @brief Copy assignment, disabled
CountingSemaphore &operator=(const CountingSemaphore &) = delete;
//! @brief Move ctor
CountingSemaphore(CountingSemaphore &&);
//! @brief Move assignment
CountingSemaphore &operator=(CountingSemaphore &&);
2020-09-18 13:15:14 +02:00
2022-02-02 10:29:30 +01:00
/* Same API as binary semaphore otherwise. acquire() can be called
* until there are not semaphores left and release() can be called
* until maxCount is reached. */
uint8_t getMaxCount() const;
private:
const uint8_t maxCount;
uint8_t initCount = 0;
2020-09-18 13:15:14 +02:00
};
#endif /* FRAMEWORK_OSAL_FREERTOS_COUNTINGSEMAPHORE_H_ */