Ownership-based wrapper for a FreeRTOS-style counting semaphore.
More...
#include <freertos_semaphore.hpp>
Ownership-based wrapper for a FreeRTOS-style counting semaphore.
Counting semaphores model a bounded resource count and can be used for producer/consumer pacing, pooled-resource limits, and event accumulation. Take/give is explicit.
Typical usage:
if(slots.Take(10)) {
(void)slots.Give();
}
Ownership-based wrapper for a FreeRTOS-style counting semaphore.
Definition freertos_semaphore.hpp:94
◆ FreeRtosCountingSemaphore() [1/2]
| c7222::FreeRtosCountingSemaphore::FreeRtosCountingSemaphore |
( |
| ) |
|
|
default |
Construct an uninitialized counting semaphore wrapper.
◆ FreeRtosCountingSemaphore() [2/2]
| c7222::FreeRtosCountingSemaphore::FreeRtosCountingSemaphore |
( |
std::uint32_t |
max_count, |
|
|
std::uint32_t |
initial_count |
|
) |
| |
Construct and initialize a counting semaphore.
- Parameters
-
| max_count | Maximum count value. |
| initial_count | Initial count value. |
◆ ~FreeRtosCountingSemaphore()
| c7222::FreeRtosCountingSemaphore::~FreeRtosCountingSemaphore |
( |
| ) |
|
Destroy semaphore resources if initialized.
◆ GetCount()
| std::uint32_t c7222::FreeRtosCountingSemaphore::GetCount |
( |
| ) |
const |
- Returns
- Current semaphore count.
◆ Give()
| bool c7222::FreeRtosCountingSemaphore::Give |
( |
| ) |
|
Return one token to the semaphore from task context.
- Returns
- true on success.
◆ GiveFromISR()
| bool c7222::FreeRtosCountingSemaphore::GiveFromISR |
( |
| ) |
|
Return one token to the semaphore from ISR context.
- Returns
- true on success.
◆ Initialize()
| bool c7222::FreeRtosCountingSemaphore::Initialize |
( |
std::uint32_t |
max_count, |
|
|
std::uint32_t |
initial_count |
|
) |
| |
Initialize (or re-initialize) a counting semaphore.
- Parameters
-
| max_count | Maximum count value. |
| initial_count | Initial count value. |
- Returns
- true on success.
◆ IsValid()
| bool c7222::FreeRtosCountingSemaphore::IsValid |
( |
| ) |
const |
- Returns
- true if the wrapper owns a valid semaphore handle.
◆ Take()
| bool c7222::FreeRtosCountingSemaphore::Take |
( |
std::uint32_t |
ticks_to_wait = 0 | ) |
|
Take one token from the semaphore.
- Parameters
-
| ticks_to_wait | Max ticks to wait (0 = non-blocking). |
- Returns
- true if a token was acquired.
The documentation for this class was generated from the following file: