QP/C  6.3.7
qxthread.h File Reference

QXK/C eXtended (blocking) thread. More...

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  QXThread
 eXtended (blocking) thread of the QXK preemptive kernel More...
 
struct  QXSemaphore
 Counting Semaphore of the QXK preemptive kernel. More...
 
struct  QXMutex
 Blocking Mutex the QXK preemptive kernel. More...
 

Macros

#define QXTHREAD_START(me_, prio_, qSto_, qLen_, stkSto_, stkLen_, param_)
 Polymorphically start an extended thread. More...
 
#define QXTHREAD_POST_X(me_, e_, margin_, sender_)   QACTIVE_POST_X(&(me_)->super, (e_), (margin_), (sender_))
 
#define QXTHREAD_NO_TIMEOUT   ((uint_fast16_t)0)
 no-timeout special timeout value when blocking on queues or semaphores More...
 
#define Q_XTHREAD_CAST(handler_)   ((QXThreadHandler)(handler_))
 Perform cast to QXThreadHandler. More...
 

Typedefs

typedef QActiveVtbl QXThreadVtbl
 Virtual Table for the QXThread class (inherited from QActiveVtbl) More...
 
typedef void(* QXThreadHandler) (QXThread *const me)
 Thread handler pointer-to-function. More...
 

Functions

void QXThread_ctor (QXThread *const me, QXThreadHandler handler, uint_fast8_t tickRate)
 constructor of an extended-thread More...
 
bool QXThread_delay (uint_fast16_t const nTicks)
 delay (block) the current extended thread for a specified # ticks More...
 
bool QXThread_delayCancel (QXThread *const me)
 cancel the delay More...
 
QEvt const * QXThread_queueGet (uint_fast16_t const nTicks)
 obtain a message from the private message queue (block if no messages) More...
 
void QXSemaphore_init (QXSemaphore *const me, uint_fast16_t count, uint_fast16_t max_count)
 initialize the counting semaphore More...
 
bool QXSemaphore_wait (QXSemaphore *const me, uint_fast16_t const nTicks)
 wait (block) on the semaphore More...
 
bool QXSemaphore_tryWait (QXSemaphore *const me)
 try wait on the semaphore (non-blocking) More...
 
bool QXSemaphore_signal (QXSemaphore *const me)
 signal (unblock) the semaphore More...
 
void QXMutex_init (QXMutex *const me, uint_fast8_t ceiling)
 initialize the QXK priority-ceiling mutex QXMutex More...
 
bool QXMutex_lock (QXMutex *const me, uint_fast16_t const nTicks)
 lock the QXK priority-ceiling mutex QXMutex More...
 
bool QXMutex_tryLock (QXMutex *const me)
 try to lock the QXK priority-ceiling mutex QXMutex More...
 
void QXMutex_unlock (QXMutex *const me)
 unlock the QXK priority-ceiling mutex QXMutex More...
 

Detailed Description

QXK/C eXtended (blocking) thread.

Definition in file qxthread.h.


Data Structure Documentation

◆ QXThread

struct QXThread

eXtended (blocking) thread of the QXK preemptive kernel

Description
QXThread represents the eXtended (blocking) thread of the QXK preemptive kernel. Each extended thread in the application must be represented by the corresponding QXThread instance
Note
Typically, QXThread is instantiated directly in the application code. The customization of the thread occurs in the QXThread_ctor(), where you provide the thred-handler function as the parameter.
See also
Usage
The following example illustrates how to instantiate an extended thread in your application.

Definition at line 71 of file qxthread.h.

Collaboration diagram for QXThread:
Collaboration graph
Data Fields
QActive super
QTimeEvt timeEvt

◆ QXSemaphore

struct QXSemaphore

Counting Semaphore of the QXK preemptive kernel.

Description
QXSemaphore is a blocking mechanism intended primarily for signaling extended threads. The semaphore is initialized with the maximum count (see 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.
See also
Usage
The following example illustrates how to instantiate the semaphore in your application.

Definition at line 190 of file qxthread.h.

Collaboration diagram for QXSemaphore:
Collaboration graph
Data Fields
QPSet waitSet set of extended-threads waiting on this semaphore
uint16_t volatile count
uint16_t max_count

◆ QXMutex

struct QXMutex

Blocking Mutex the QXK preemptive kernel.

Description
QXMutex is a blocking mutual exclusion mechanism that can also apply the priority ceiling protocol to avoid unbounded priority inversion (if initialized with a non-zero ceiling priority, see QXMutex_init()). In that case, QXMutex requires its own uinque QP priority level, which cannot be used by any thread or any other QXMutex. If initialzied with zero ceiling priority, QXMutex does not use the priority ceiling protocol and does not require a unique QP priority (see QXMutex_init()). QXMutex is recursive (reentrant), which means that it can be locked mutiliple times (up to 255 levels) by the same thread without causing deadlock. QXMutex is primarily intended for the extened (blocking) threads, but can also be used by the basic threads through the non-blocking QXMutex_tryLock() API.
Note
QXMutex should be used in situations when at least one of the extended threads contending for the mutex blocks while holding the mutex (between the QXMutex_lock() and QXMutex_unlock() operations). If no blocking is needed while holding the mutex, the more efficient non-blocking mechanism of selective QXK scheduler locking should be used instead. Selective scheduler locking is available for both basic threads and extendedthreads", so it is applicable to situations where resources are shared among all these threads.
See also
Usage
The following example illustrates how to instantiate the mutex in your application.

Definition at line 252 of file qxthread.h.

Collaboration diagram for QXMutex:
Collaboration graph
Data Fields
QPSet waitSet set of extended-threads waiting on this mutex
uint8_t volatile lockNest
uint8_t volatile holderPrio
uint8_t ceiling

Macro Definition Documentation

◆ QXTHREAD_START

#define QXTHREAD_START (   me_,
  prio_,
  qSto_,
  qLen_,
  stkSto_,
  stkLen_,
  param_ 
)
Value:
((*((QActiveVtbl const *)((me_)->super.super.vptr))->start)( \
&(me_)->super, (prio_), (QEvt const **)(qSto_), (qLen_), \
(stkSto_), (stkLen_), (param_)))
Virtual table for the QActive class.
Definition: qf.h:170
Event structure.
Definition: qep.h:153

Polymorphically start an extended thread.

Description
Starts execution of the thread and registers the thread with the framework.
Parameters
[in,out]me_pointer (see Object Orientation)
[in]prio_priority of the extended-thread
[in]qSto_pointer to the storage for the ring buffer of the message queue (possibly NULL)
[in]qLen_length of the message queue [events] (possibly 0)
[in]stkSto_pointer to the stack storage (required)
[in]stkSize_stack size [bytes]
[in]param_pointer to the additional port-specific parameter(s) (might be NULL).
Usage
int main() {
. . .
/* stack for the QXK's idle thread */
static uint64_t idleStackSto[32];
Test_ctor(); /* instantiate the Test "naked" thread */
QF_init(); /* initialize the framework */
BSP_init(); /* initialize the Board Support Package */
/* initialize QXK... */
QXK_init(idleStackSto, sizeof(idleStackSto));
/* initialize publish-subscribe... */
QF_psInit(subscrSto, Q_DIM(subscrSto));
/* initialize event pools... */
QF_poolInit(smlPoolSto, sizeof(smlPoolSto), sizeof(smlPoolSto[0]));
/* start the active objects... */
QACTIVE_START(AO_Table, /* AO to start */
(uint_fast8_t)(N_PHILO + 2), /* QP priority of the AO */
tableQueueSto, /* event queue storage */
Q_DIM(tableQueueSto), /* queue length [events] */
tableStackSto, /* stack storage */
sizeof(tableStackSto), /* stack size [bytes] */
(QEvt *)0); /* initialization event */
. . .
/* start the "naked" thread */
QXTHREAD_START(XT_Test, /* Thread to start */
(uint_fast8_t)10U, /* QP priority of the thread */
testQueueSto, /* message queue storage */
Q_DIM(testQueueSto), /* message length [events] */
testStackSto, /* stack storage */
sizeof(testStackSto), /* stack size [bytes] */
(QEvt *)0); /* initialization event */
return QF_run(); /* run the QF application */
}

Definition at line 101 of file qxthread.h.

◆ QXTHREAD_POST_X

#define QXTHREAD_POST_X (   me_,
  e_,
  margin_,
  sender_ 
)    QACTIVE_POST_X(&(me_)->super, (e_), (margin_), (sender_))
Description
This macro does not assert if the queue overflows and cannot accept the event with the specified margin of free slots remaining.
Parameters
[in,out]me_pointer (see Object Orientation)
[in]e_pointer to the event to post
[in]margin_the minimum free slots in the queue, which must still be available after posting the event. The special value QF_NO_MARGIN causes asserting failure in case event allocation fails.
[in]sender_pointer to the sender object.
Returns
'true' if the posting succeeded, and 'false' if the posting failed due to insufficient margin of free slots available in the queue.
Note
The sender_ parameter is actually only used when QS tracing is enabled (macro Q_SPY is defined). When QS software tracing is disabled, the QXTHREAD_POST_X() macro does not pass the sender_ argument, so the overhead of passing this extra argument is entirely avoided.
The pointer to the sender object is not necessarily a pointer to an active object. In fact, if QXTHREAD_POST_X() is called from an interrupt or other context, you can create a unique object just to unambiguously identify the sender of the event.
Usage
extern QActive *AO_Table;
. . .
/* typically inside a state machine action */
TableEvt *pe;
Q_NEW_X(pe, TableEvt, 5U, HUNGRY_SIG); /* dynamic alloc, margin==5 */
if (pe != (TableEvt *)0) {
pe->philNum = me->num;
QACTIVE_POST_X(AO_Table, &pe->super, 3U, me); /* margin==3 */
}
. . .

Definition at line 145 of file qxthread.h.

◆ QXTHREAD_NO_TIMEOUT

#define QXTHREAD_NO_TIMEOUT   ((uint_fast16_t)0)

no-timeout special timeout value when blocking on queues or semaphores

Definition at line 158 of file qxthread.h.

◆ Q_XTHREAD_CAST

#define Q_XTHREAD_CAST (   handler_)    ((QXThreadHandler)(handler_))

Perform cast to QXThreadHandler.

Description
This macro encapsulates the cast of a specific thread handler function pointer to QXThreadHandler, which violates MISRA-C 2004 rule 11.4(adv). This macro helps to localize this deviation.

Definition at line 167 of file qxthread.h.

Typedef Documentation

◆ QXThreadVtbl

Virtual Table for the QXThread class (inherited from QActiveVtbl)

Note
QXThread inherits QActive without adding any new virtual functions and therefore, QXThreadVtbl is typedef'ed as QActiveVtbl.

Definition at line 82 of file qxthread.h.

◆ QXThreadHandler

typedef void(* QXThreadHandler) (QXThread *const me)

Thread handler pointer-to-function.

Definition at line 107 of file qxthread.h.

Function Documentation

◆ QXThread_ctor()

void QXThread_ctor ( QXThread *const  me,
QXThreadHandler  handler,
uint_fast8_t  tickRate 
)

constructor of an extended-thread

◆ QXThread_delay()

bool QXThread_delay ( uint_fast16_t const  nTicks)

delay (block) the current extended thread for a specified # ticks

◆ QXThread_delayCancel()

bool QXThread_delayCancel ( QXThread *const  me)

cancel the delay

◆ QXThread_queueGet()

QEvt const* QXThread_queueGet ( uint_fast16_t const  nTicks)

obtain a message from the private message queue (block if no messages)

◆ QXSemaphore_init()

void QXSemaphore_init ( QXSemaphore *const  me,
uint_fast16_t  count,
uint_fast16_t  max_count 
)

initialize the counting semaphore

◆ QXSemaphore_wait()

bool QXSemaphore_wait ( QXSemaphore *const  me,
uint_fast16_t const  nTicks 
)

wait (block) on the semaphore

◆ QXSemaphore_tryWait()

bool QXSemaphore_tryWait ( QXSemaphore *const  me)

try wait on the semaphore (non-blocking)

◆ QXSemaphore_signal()

bool QXSemaphore_signal ( QXSemaphore *const  me)

signal (unblock) the semaphore

◆ QXMutex_init()

void QXMutex_init ( QXMutex *const  me,
uint_fast8_t  ceiling 
)

initialize the QXK priority-ceiling mutex QXMutex

◆ QXMutex_lock()

bool QXMutex_lock ( QXMutex *const  me,
uint_fast16_t const  nTicks 
)

lock the QXK priority-ceiling mutex QXMutex

◆ QXMutex_tryLock()

bool QXMutex_tryLock ( QXMutex *const  me)

try to lock the QXK priority-ceiling mutex QXMutex

◆ QXMutex_unlock()

void QXMutex_unlock ( QXMutex *const  me)

unlock the QXK priority-ceiling mutex QXMutex