QP/C++  6.5.1
QXThread Class Reference

Extended (blocking) thread of the QXK preemptive kernel. More...

#include <qxthread.h>

Inheritance diagram for QXThread:
Inheritance graph
Collaboration diagram for QXThread:
Collaboration graph

Public Member Functions

 QXThread (QXThreadHandler const handler, uint_fast8_t const tickRate=static_cast< uint_fast8_t >(0))
 public constructor More...
 
bool delayCancel (void)
 cancel the delay More...
 
virtual void init (QEvt const *const e)
 Executes the top-most initial transition in QP::QMsm. More...
 
virtual void init (void)
 Executes the top-most initial transition in QP::QHsm. More...
 
virtual void dispatch (QEvt const *const e)
 Dispatches an event to QMsm. More...
 
virtual void start (uint_fast8_t const prio, QEvt const *qSto[], uint_fast16_t const qLen, void *const stkSto, uint_fast16_t const stkSize, QEvt const *const ie)
 Starts execution of an extended thread and registers the thread with the framework. More...
 
virtual void start (uint_fast8_t const prio, QEvt const *qSto[], uint_fast16_t const qLen, void *const stkSto, uint_fast16_t const stkSize)
 Overloaded start function (no initialization event) More...
 
virtual bool post_ (QEvt const *const e, uint_fast16_t const margin, void const *const sender)
 
virtual void postLIFO (QEvt const *const e)
 Posts an event directly to the event queue of the active object using the Last-In-First-Out (LIFO) policy. More...
 
bool isBlockedOn (void const *const obj=static_cast< void const * >(0)) const
 get the blocking object for this thread (NULL if not blocked) More...
 
- Public Member Functions inherited from QActive
void unsubscribeAll (void) const
 Un-subscribes from the delivery of all signals to the active object. More...
 
void subscribe (enum_t const sig) const
 Subscribes for delivery of signal sig to the active object. More...
 
void unsubscribe (enum_t const sig) const
 Un-subscribes from the delivery of signal sig to the active object. More...
 
bool defer (QEQueue *const eq, QEvt const *const e) const
 Defer an event to a given separate event queue. More...
 
bool recall (QEQueue *const eq)
 Recall a deferred event from a given event queue. More...
 
uint_fast16_t flushDeferred (QEQueue *const eq) const
 Flush the specified deferred queue 'eq'. More...
 
uint_fast8_t getPrio (void) const
 Get the priority of the active object. More...
 
void setPrio (uint_fast8_t const prio)
 Set the priority of the active object. More...
 
void setAttr (uint32_t attr1, void const *attr2=static_cast< void * >(0))
 Generic setting of additional attributes (useful in QP ports) More...
 
QEvt const * get_ (void)
 Get an event from the event queue of an active object. More...
 
- Public Member Functions inherited from QHsm
virtual ~QHsm ()
 virtual destructor More...
 
bool isIn (QStateHandler const s)
 Tests if a given state is part of the current active state configuration. More...
 
QStateHandler state (void) const
 Obtain the current state (state handler function) More...
 
QStateHandler childState (QStateHandler const parent)
 Obtain the current active child state of a given parent. More...
 

Static Public Member Functions

static bool delay (uint_fast16_t const nTicks)
 delay (block) the current extended thread for a specified # ticks More...
 
static QEvt const * queueGet (uint_fast16_t const nTicks=QXTHREAD_NO_TIMEOUT)
 obtain a message from the private message queue (block if no messages) More...
 
- Static Public Member Functions inherited from QHsm
static QState top (void *const me, QEvt const *const e)
 the top-state. More...
 

Private Member Functions

void block_ (void) const
 
void unblock_ (void) const
 
void teArm_ (enum_t const sig, uint_fast16_t const nTicks)
 
bool teDisarm_ (void)
 

Private Attributes

QTimeEvt m_timeEvt
 time event to handle blocking timeouts More...
 

Friends

class QXSemaphore
 
class QXMutex
 

Additional Inherited Members

- Data Fields inherited from QActive
uint8_t m_prio
 QF priority (1..QF_MAX_ACTIVE) of this active object. More...
 
- Protected Types inherited from QHsm
enum  ReservedHsmSignals { Q_ENTRY_SIG = 1, Q_EXIT_SIG, Q_INIT_SIG }
 
- Protected Member Functions inherited from QActive
 QActive (QStateHandler const initial)
 protected constructor (abstract class) More...
 
- Protected Member Functions inherited from QHsm
 QHsm (QStateHandler const initial)
 Protected constructor of QHsm. More...
 
QState tran (QStateHandler const target)
 Helper function to specify a state transition. More...
 
QState tran_hist (QStateHandler const hist)
 Helper function to specify a transition to history. More...
 
QState super (QStateHandler const superstate)
 Helper function to specify the superstate of a given state. More...
 
QState qm_tran (void const *const tatbl)
 Helper function to specify a regular state transition in a QM state-handler. More...
 
QState qm_tran_hist (QMState const *const hist, void const *const tatbl)
 Helper function to specifiy a transition to history in a QM state-handler. More...
 
QState qm_tran_init (void const *const tatbl)
 Helper function to specify an initial state transition in a QM state-handler. More...
 
QState qm_tran_ep (void const *const tatbl)
 Helper function to specify a transition to an entry point to a submachine state in a QM state-handler. More...
 
QState qm_tran_xp (QActionHandler const xp, void const *const tatbl)
 Helper function to specify a transition to an exit point from a submachine state in a QM state-handler. More...
 
QState qm_entry (QMState const *const s)
 Helper function to specify a state entry in a QM state-handler. More...
 
QState qm_exit (QMState const *const s)
 Helper function to specify a state exit in a QM state-handler. More...
 
QState qm_sm_exit (QMState const *const s)
 Helper function to specify a submachine exit in a QM state-handler. More...
 
QState qm_super_sub (QMState const *const s)
 Helper function to call in a QM state-handler when it passes the event to the host submachine state to handle an event. More...
 
- Static Protected Attributes inherited from QHsm
static QState const Q_RET_SUPER = static_cast<QState>(0)
 event passed to the superstate to handle More...
 
static QState const Q_RET_SUPER_SUB = static_cast<QState>(1)
 event passed to submachine superstate More...
 
static QState const Q_RET_UNHANDLED = static_cast<QState>(2)
 event unhandled due to a guard evaluating to 'false' More...
 
static QState const Q_RET_HANDLED = static_cast<QState>(3)
 event handled (internal transition) More...
 
static QState const Q_RET_IGNORED = static_cast<QState>(4)
 event silently ignored (bubbled up to top) More...
 
static QState const Q_RET_ENTRY = static_cast<QState>(5)
 state entry action executed More...
 
static QState const Q_RET_EXIT = static_cast<QState>(6)
 state exit action executed More...
 
static QState const Q_RET_NULL = static_cast<QState>(7)
 return value without any effect More...
 
static QState const Q_RET_TRAN = static_cast<QState>(8)
 regular transition taken More...
 
static QState const Q_RET_TRAN_INIT = static_cast<QState>(9)
 initial transition taken More...
 
static QState const Q_RET_TRAN_EP = static_cast<QState>(10)
 entry-point transition into a submachine More...
 
static QState const Q_RET_TRAN_HIST = static_cast<QState>(11)
 transition to history of a given state More...
 
static QState const Q_RET_TRAN_XP = static_cast<QState>(12)
 exit-point transition out of a submachine More...
 

Detailed Description

Extended (blocking) thread of the QXK preemptive kernel.

Description
QP::QXThread represents the extended (blocking) thread of the QXK kernel. Each blocking thread in the application must be represented by the corresponding QP::QXThread instance
Note
Typically QP::QXThread is instantiated directly in the application code. The customization of the thread occurs in the constructor, where you provide the thred-handler function as the parameter.
See also
QP::QActive
Usage
The following example illustrates how to instantiate and use an extended thread in your application.
void main_blinky(QP::QXThread * const me) { // thread function
while (1) {
for (uint32_t volatile i; = 1500U; i != 0U; --i) {
BSP_ledGreenOn();
BSP_ledGreenOff();
}
QP::QXThread::delay(1U); // block for 1 tick
}
}
QP::QXThread blinky(&main_blinky, 0U); // QXK extended-thread object
uint32_t stack_blinky[80]; // stack for the thread
int main() {
. . .
// initialize and start blinky thread
blinky.start(5U, // priority
(void *)0, 0, // message queue (not used)
stack_blinky, sizeof(stack_blinky), // stack
static_cast<QP::QEvt *>(0)); // initialization event
. . .
return QP::QF::run(); // run the application
}

Definition at line 71 of file qxthread.h.

Constructor & Destructor Documentation

◆ QXThread()

QXThread ( QXThreadHandler const  handler,
uint_fast8_t const  tickRate = static_cast< uint_fast8_t >(0) 
)

public constructor

Member Function Documentation

◆ delay()

static bool delay ( uint_fast16_t const  nTicks)
static

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

◆ delayCancel()

bool delayCancel ( void  )

cancel the delay

◆ queueGet()

static QEvt const* queueGet ( uint_fast16_t const  nTicks = QXTHREAD_NO_TIMEOUT)
static

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

◆ init() [1/2]

virtual void init ( QEvt const *const  e)
virtual

Executes the top-most initial transition in QP::QMsm.

Reimplemented from QHsm.

◆ init() [2/2]

virtual void init ( void  )
inlinevirtual

Executes the top-most initial transition in QP::QHsm.

Reimplemented from QHsm.

Definition at line 91 of file qxthread.h.

◆ dispatch()

virtual void dispatch ( QEvt const *const  e)
virtual

Dispatches an event to QMsm.

Reimplemented from QHsm.

◆ start() [1/2]

virtual void start ( uint_fast8_t const  prio,
QEvt const *  qSto[],
uint_fast16_t const  qLen,
void *const  stkSto,
uint_fast16_t const  stkSize,
QEvt const *const  ie 
)
virtual

Starts execution of an extended thread and registers the thread with the framework.

Reimplemented from QActive.

◆ start() [2/2]

virtual void start ( uint_fast8_t const  prio,
QEvt const *  qSto[],
uint_fast16_t const  qLen,
void *const  stkSto,
uint_fast16_t const  stkSize 
)
inlinevirtual

Overloaded start function (no initialization event)

Reimplemented from QActive.

Definition at line 104 of file qxthread.h.

◆ post_()

virtual bool post_ ( QEvt const *const  e,
uint_fast16_t const  margin,
void const *const  sender 
)
virtual
Description
Direct event posting is the simplest asynchronous communication method available in QF.
Parameters
[in,out]epointer to the event to be posted
[in]marginnumber of required free slots in the queue after posting the event. The special value QP::QF_NO_MARGIN means that this function will assert if posting fails.
Returns
'true' (success) if the posting succeeded (with the provided margin) and 'false' (failure) when the posting fails.
Attention
Should be called only via the macro POST() or POST_X().
Note
The QP::QF_NO_MARGIN value of the margin argument is special and denotes situation when the post() operation is assumed to succeed (event delivery guarantee). An assertion fires, when the event cannot be delivered in this case.
Usage
extern QActive *AO_Table;
QP::QState Philo::hungry(Philo * const me, QP::QEvt const * const e) {
QP::QState status;
switch (e->sig) {
case Q_ENTRY_SIG: {
TableEvt *pe = Q_NEW(TableEvt, HUNGRY_SIG);
pe->philoNum = PHILO_ID(me);
AO_Table->POST(pe, me);
status = Q_HANDLED();
break;
}
. . .
default: {
status = Q_SUPER(&QHsm::top);
break;
}
}
return status;
}
See also
QActive::postLIFO()
Precondition
event pointer must be valid

Reimplemented from QActive.

◆ postLIFO()

virtual void postLIFO ( QEvt const *const  e)
virtual

Posts an event directly to the event queue of the active object using the Last-In-First-Out (LIFO) policy.

Reimplemented from QActive.

◆ isBlockedOn()

bool isBlockedOn ( void const *const  obj = static_cast<void const *>(0)) const
inline

get the blocking object for this thread (NULL if not blocked)

Definition at line 126 of file qxthread.h.

◆ block_()

void block_ ( void  ) const
private

◆ unblock_()

void unblock_ ( void  ) const
private

◆ teArm_()

void teArm_ ( enum_t const  sig,
uint_fast16_t const  nTicks 
)
private

◆ teDisarm_()

bool teDisarm_ ( void  )
private

Friends And Related Function Documentation

◆ QXSemaphore

friend class QXSemaphore
friend

Definition at line 142 of file qxthread.h.

◆ QXMutex

friend class QXMutex
friend

Definition at line 143 of file qxthread.h.

Field Documentation

◆ m_timeEvt

QTimeEvt m_timeEvt
private

time event to handle blocking timeouts

Definition at line 139 of file qxthread.h.


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