QP/C++  6.6.0
QXSemaphore Class Reference

Counting Semaphore of the QXK preemptive kernel. More...

#include <qxthread.hpp>

Collaboration diagram for QXSemaphore:
Collaboration graph

Public Member Functions

void init (uint_fast16_t const count, uint_fast16_t const max_count=static_cast< uint_fast16_t >(0xFFFF))
 initialize the counting semaphore More...
bool wait (uint_fast16_t const nTicks=QXTHREAD_NO_TIMEOUT)
 wait (block) on the semaphore More...
bool tryWait (void)
 try wait on the semaphore (non-blocking) More...
bool signal (void)
 signal (unblock) the semaphore More...

Private Attributes

QPSet m_waitSet
 set of extended threads waiting on this semaphore More...
uint16_t volatile m_count
 semaphore up-down counter More...
uint16_t m_max_count
 maximum value of the semaphore counter More...

Detailed Description

Counting Semaphore of the QXK preemptive kernel.

QP::QXSemaphore is a blocking mechanism intended primarily for signaling extended threads. The semaphore is initialized with the maximum count (see QP::QXSemaphore::init()), which allows you to create a binary semaphore (when the maximum count is 1) and counting semaphore when the maximum count is > 1.
The following example illustrates how to instantiate and use the semaphore in your application.
QXSemaphore BTN_sema; // semaphore to signal a button press
int main() {
. . .
// initialize the BTN_sema semaphore as binary, signaling semaphore
BTN_sema.init(0U, // initial semaphore count (singaling semaphore)
1U); // maximum semaphore count (binary semaphore)
. . .
void main_threadXYZ(QXThread * const me) {
while (1) {
. . .
BTN_sema.wait(QXTHREAD_NO_TIMEOUT); // timeout for waiting
. . .
void GPIO_Handler(void) {
. . .
. . .

Definition at line 161 of file qxthread.hpp.

Member Function Documentation

◆ init()

void init ( uint_fast16_t const  count,
uint_fast16_t const  max_count = static_cast< uint_fast16_t >(0xFFFF) 

initialize the counting semaphore

◆ wait()

bool wait ( uint_fast16_t const  nTicks = QXTHREAD_NO_TIMEOUT)

wait (block) on the semaphore

◆ tryWait()

bool tryWait ( void  )

try wait on the semaphore (non-blocking)

◆ signal()

bool signal ( void  )

signal (unblock) the semaphore

Field Documentation

◆ m_waitSet

QPSet m_waitSet

set of extended threads waiting on this semaphore

Definition at line 178 of file qxthread.hpp.

◆ m_count

uint16_t volatile m_count

semaphore up-down counter

Definition at line 179 of file qxthread.hpp.

◆ m_max_count

uint16_t m_max_count

maximum value of the semaphore counter

Definition at line 180 of file qxthread.hpp.

The documentation for this class was generated from the following file:
no-timeout sepcification when blocking on queues or semaphores
Definition: qxthread.hpp:43