ELEC-C7222
Libraries for ELEC C7222 Course Work
Loading...
Searching...
No Matches
c7222::FreeRtosCountingSemaphore Class Reference

Ownership-based wrapper for a FreeRTOS-style counting semaphore. More...

#include <freertos_semaphore.hpp>

Inheritance diagram for c7222::FreeRtosCountingSemaphore:
Inheritance graph
Collaboration diagram for c7222::FreeRtosCountingSemaphore:
Collaboration graph

Public Member Functions

 FreeRtosCountingSemaphore ()=default
 Construct an uninitialized counting semaphore wrapper.
 
 FreeRtosCountingSemaphore (std::uint32_t max_count, std::uint32_t initial_count)
 Construct and initialize a counting semaphore.
 
bool Initialize (std::uint32_t max_count, std::uint32_t initial_count)
 Initialize (or re-initialize) a counting semaphore.
 
 ~FreeRtosCountingSemaphore ()
 Destroy semaphore resources if initialized.
 
bool Take (std::uint32_t ticks_to_wait=0)
 Take one token from the semaphore.
 
bool Give ()
 Return one token to the semaphore from task context.
 
bool GiveFromISR ()
 Return one token to the semaphore from ISR context.
 
std::uint32_t GetCount () const
 
bool IsValid () const
 
- Public Member Functions inherited from c7222::NonCopyable
 NonCopyable (const NonCopyable &)=delete
 
NonCopyableoperator= (const NonCopyable &)=delete
 
 NonCopyable (NonCopyable &&)=default
 
NonCopyableoperator= (NonCopyable &&)=default
 
- Public Member Functions inherited from c7222::NonMovable
 NonMovable (const NonMovable &)=default
 
NonMovableoperator= (const NonMovable &)=default
 
 NonMovable (NonMovable &&)=delete
 
NonMovableoperator= (NonMovable &&)=delete
 

Additional Inherited Members

- Protected Member Functions inherited from c7222::NonCopyableNonMovable
 NonCopyableNonMovable ()=default
 
 ~NonCopyableNonMovable ()=default
 
- Protected Member Functions inherited from c7222::NonCopyable
 NonCopyable ()=default
 
 ~NonCopyable ()=default
 
- Protected Member Functions inherited from c7222::NonMovable
 NonMovable ()=default
 
 ~NonMovable ()=default
 

Detailed Description

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)) {
// use one resource slot
(void)slots.Give();
}
Ownership-based wrapper for a FreeRTOS-style counting semaphore.
Definition freertos_semaphore.hpp:94

Constructor & Destructor Documentation

◆ 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_countMaximum count value.
initial_countInitial count value.

◆ ~FreeRtosCountingSemaphore()

c7222::FreeRtosCountingSemaphore::~FreeRtosCountingSemaphore ( )

Destroy semaphore resources if initialized.

Member Function Documentation

◆ 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_countMaximum count value.
initial_countInitial 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_waitMax ticks to wait (0 = non-blocking).
Returns
true if a token was acquired.

The documentation for this class was generated from the following file: