theCore C++ embedded framework
ecl::binary_semaphore Class Reference

FreeRTOS-based semaphore. More...

#include </home/travis/build/forGGe/theCore/lib/thread/posix/export/ecl/thread/semaphore.hpp>

Public Member Functions

 binary_semaphore ()
 
 ~binary_semaphore ()
 
void signal ()
 Signals a semaphore. More...
 
void wait ()
 Waits a semaphore. More...
 
bool try_wait (std::chrono::milliseconds ms=std::chrono::milliseconds(0))
 Tries to wait on semaphore without lock. More...
 
 binary_semaphore (const binary_semaphore &)=delete
 
binary_semaphoreoperator= (const binary_semaphore &)=delete
 
constexpr binary_semaphore ()
 Constructs semaphore. More...
 
void signal ()
 Signals semaphore, sets counter to 1. More...
 
void wait ()
 Waits for semaphore, sets counter to 0. More...
 
bool try_wait (std::chrono::milliseconds ms=std::chrono::milliseconds(0))
 Tries to wait for semaphore signal. More...
 
 binary_semaphore (const binary_semaphore &)=delete
 
binary_semaphoreoperator= (const binary_semaphore &)=delete
 
 binary_semaphore ()
 Constructs semaphore. More...
 
void signal ()
 Signals semaphore, sets counter to 1. More...
 
void wait ()
 Waits for semaphore, sets counter to 0. More...
 
bool try_wait (std::chrono::milliseconds ms=std::chrono::milliseconds(0))
 Tries to wait for semaphore signal. More...
 
 binary_semaphore (const binary_semaphore &)=delete
 
binary_semaphoreoperator= (const binary_semaphore &)=delete
 

Detailed Description

FreeRTOS-based semaphore.

Binary semaphore.

Naive binary semaphore, acting like spinlock of some kind.

This semaphore is specific. It can only be raisen or cleared. Default state is cleared, so calling wait() would block until someone will call signal()

Suitable for targets without OS included and without WFI/WFE enabled. Useful during bring-up of new platforms. Main requirement - atomic support. Can take only two values - 0 or 1.

Can take only two values - 0 or 1.

Constructor & Destructor Documentation

◆ binary_semaphore() [1/6]

ecl::binary_semaphore::binary_semaphore ( )

◆ ~binary_semaphore()

ecl::binary_semaphore::~binary_semaphore ( )

◆ binary_semaphore() [2/6]

ecl::binary_semaphore::binary_semaphore ( const binary_semaphore )
delete

◆ binary_semaphore() [3/6]

constexpr ecl::binary_semaphore::binary_semaphore ( )
inline

Constructs semaphore.

◆ binary_semaphore() [4/6]

ecl::binary_semaphore::binary_semaphore ( const binary_semaphore )
delete

◆ binary_semaphore() [5/6]

ecl::binary_semaphore::binary_semaphore ( )

Constructs semaphore.

◆ binary_semaphore() [6/6]

ecl::binary_semaphore::binary_semaphore ( const binary_semaphore )
delete

Member Function Documentation

◆ signal() [1/3]

void ecl::binary_semaphore::signal ( )

Signals a semaphore.

Can be called from ISR

Here is the call graph for this function:

◆ wait() [1/3]

void ecl::binary_semaphore::wait ( )

Waits a semaphore.

Default state is cleared, so calling wait() would block until someone will call signal()

◆ try_wait() [1/3]

bool ecl::binary_semaphore::try_wait ( std::chrono::milliseconds  ms = std::chrono::milliseconds(0))

Tries to wait on semaphore without lock.

Parameters
[in]msMilliseconds to wait.
Return values
falseSomeone already waits a semaphore.
trueSemaphore counter decremented.

◆ operator=() [1/3]

binary_semaphore& ecl::binary_semaphore::operator= ( const binary_semaphore )
delete

◆ signal() [2/3]

void ecl::binary_semaphore::signal ( )

Signals semaphore, sets counter to 1.

Can be called from ISR.

◆ wait() [2/3]

void ecl::binary_semaphore::wait ( )

Waits for semaphore, sets counter to 0.

◆ try_wait() [2/3]

bool ecl::binary_semaphore::try_wait ( std::chrono::milliseconds  ms = std::chrono::milliseconds(0))

Tries to wait for semaphore signal.

Will wait for semaphore signal with provided timeout. If no parameter given then it will immediately exit if there is no pending signals.

Parameters
[in]msMilliseconds to wait.
Return values
trueSemaphore signal consumed, counter decreased.
falseNothing to consume.

◆ operator=() [2/3]

binary_semaphore& ecl::binary_semaphore::operator= ( const binary_semaphore )
delete

◆ signal() [3/3]

void ecl::binary_semaphore::signal ( )

Signals semaphore, sets counter to 1.

Can be called from ISR.

◆ wait() [3/3]

void ecl::binary_semaphore::wait ( )

Waits for semaphore, sets counter to 0.

◆ try_wait() [3/3]

bool ecl::binary_semaphore::try_wait ( std::chrono::milliseconds  ms = std::chrono::milliseconds(0))

Tries to wait for semaphore signal.

Will wait for semaphore signal with provided timeout. If no parameter given then it will immediatelly exit if there is no pending signals.

Parameters
[in]msMilliseconds to wait.
Return values
trueSemaphore signal consumed, counter decreased.
falseNothing to consume.

◆ operator=() [3/3]

binary_semaphore& ecl::binary_semaphore::operator= ( const binary_semaphore )
delete

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