QP/C++  6.5.1
QXSemaphore Class Reference

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

#include <qxthread.h>

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.

Description
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.
Usage
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) {
. . .
BTN_sema.signal();
. . .
}

Definition at line 161 of file qxthread.h.

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
private

set of extended threads waiting on this semaphore

Definition at line 178 of file qxthread.h.

◆ m_count

uint16_t volatile m_count
private

semaphore up-down counter

Definition at line 179 of file qxthread.h.

◆ m_max_count

uint16_t m_max_count
private

maximum value of the semaphore counter

Definition at line 180 of file qxthread.h.


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