QP/C  5.9.3
qxk_sema.c File Reference

QXK preemptive kernel semaphore functions. More...

#include "qf_port.h"
#include "qxk_pkg.h"
#include "qassert.h"
#include "qs_port.h"

Go to the source code of this file.


#define QP_IMPL   /* this is QP implementation */


void QXSemaphore_init (QXSemaphore *const me, uint_fast16_t count)
 initialize the counting semaphore More...
bool QXSemaphore_wait (QXSemaphore *const me, uint_fast16_t const nTicks, uint_fast8_t const tickRate)
 wait (block) on the semaphore More...
void QXSemaphore_signal (QXSemaphore *const me)
 signal (unblock) the semaphore More...

Detailed Description

QXK preemptive kernel semaphore functions.

Definition in file qxk_sema.c.

Function Documentation

◆ QXSemaphore_init()

void QXSemaphore_init ( QXSemaphore *const  me,
uint_fast16_t  count 

initialize the counting semaphore

Initializes a semaphore with the specified count. If the semaphore is used for resource sharing, the initial value of the semaphore count should be set to the number of identical resources guarded by the semaphore. If the semaphore is used as a signaling mechanism, the initial count should set to 0.
[in,out]mepointer (see Object Orientation)
[in]countinitial value of the semaphore counter
QXSemaphore_init() must be called before the semaphore can be used (signaled or waited on).

Definition at line 73 of file qxk_sema.c.

◆ QXSemaphore_signal()

void QXSemaphore_signal ( QXSemaphore *const  me)

signal (unblock) the semaphore

If the semaphore counter value is 0 or more, it is incremented, and this function returns to its caller. If the extended threads are waiting for the semaphore to be signaled, QXSemaphore_signal() removes the highest- priority thread waiting for the semaphore from the waiting list and makes this thread ready-to-run. The QXK scheduler is then called to determine if the awakened thread is now the highest-priority thread that is ready-to-run.
[in,out]mepointer (see Object Orientation)
A semaphore can be signaled from many places, including from ISRs, basic threads (AOs), and extended threads.

Definition at line 157 of file qxk_sema.c.

◆ QXSemaphore_wait()

bool QXSemaphore_wait ( QXSemaphore *const  me,
uint_fast16_t const  nTicks,
uint_fast8_t const  tickRate 

wait (block) on the semaphore

When an extended thread calls QXSemaphore_wait() and the value of the semaphore counter is greater than 0, QXSemaphore_wait() decrements the semaphore counter and returns (true) to its caller. However, if the value of the semaphore counter is 0, the function places the calling thread in the waiting list for the semaphore. The thread waits until the semaphore is signaled by calling QXSemaphore_signal(), or the specified timeout expires. If the semaphore is signaled before the timeout expires, QXK resumes the highest-priority extended thread waiting for the semaphore.
[in,out]mepointer (see Object Orientation)
[in]nTicksnumber of clock ticks (at the associated rate) to wait for the semaphore. The value of QXTHREAD_NO_TIMEOUT indicates that no timeout will occur and the semaphore will wait indefinitely.
[in]tickRatesystem clock tick rate serviced in this call.
true if the semaphore has been signaled, and false if the timeout occured.
Multiple extended threads can wait for a given semahpre.

Definition at line 103 of file qxk_sema.c.