QP/C
Data Fields
QActive Struct Reference

Active Object structure. More...

#include <qf.h>

Data Fields

QF_ACTIVE_SUPER_ super
QF_EQUEUE_TYPE eQueue
 OS-dependent event-queue type.
uint8_t prio
 QF priority associated with the active object.
uint8_t running
 The Boolean loop variable determining if the thread routine of the active object is running.

Detailed Description

Active Object structure.

QActive is the base structure for derivation of active objects. Active objects in QF are encapsulated tasks (each embedding a state machine and an event queue) that communicate with one another asynchronously by sending and receiving events. Within an active object, events are processed sequentially in a run-to-completion (RTC) fashion, while QF encapsulates all the details of thread-safe event exchange and queuing.

Note:
QActive is not intended to be instantiated directly, but rather serves as the base structure for derivation of active objects in the application code.

The following example illustrates how to derive an active object from QActive. Please note that the QActive member super_ is defined as the FIRST member of the derived struct.

typedef struct PhilosopherTag {
    QActive super;                                  /* derives from QActive */
    uint8_t num;                              /* number of this philosopher */
    QTimeEvt timeEvt;                       /* to timeout thining or eating */
} Philosopher;
See also:
::QActiveTag for the description of the data members
Encapsulation and Single Inheritance in C

Definition at line 140 of file qf.h.


Field Documentation

OS-dependent event-queue type.

The type of the queue depends on the underlying operating system or a kernel. Many kernels support "message queues" that can be adapted to deliver QF events to the active object. Alternatively, QF provides a native event queue implementation that can be used as well.

The native QF event queue is configured by defining the macro QF_EQUEUE_TYPE as QEQueue.

Definition at line 156 of file qf.h.

Referenced by QActive_postFIFO(), and QActive_start().

uint8_t QActive::prio

QF priority associated with the active object.

See also:
QActive_start()

Definition at line 182 of file qf.h.

Referenced by QActive_start(), QF_add_(), and QF_remove_().

The Boolean loop variable determining if the thread routine of the active object is running.

This flag is only used with the traditional loop-structured thread routines. Clearing this flag breaks out of the thread loop, which is often the cleanest way to terminate the thread. The following example illustrates the thread routine for Win32:

/* thread routine for Win32 _beginthread() */
static void __cdecl run(void *me) { /* the exact signature for _beginthread */
    do {
        QEvent const *e;

        QACTIVE_GET_((QActive *)me, e);               /* wait for the event */
        QF_ACTIVE_DISPATCH_(me, e);   /* dispatch to the active object's SM */
        QF_gc(e);    /* check if the event is garbage, and collect it if so */

    } while (((QActive *)me)->prio > (uint8_t)0);

    QActive_unsubscribeAll((QActive *)me);  /* unsubscribe from all signals */
    QF_remove_((QActive *)me); /* remove this object from any subscriptions */

    _endthread();    /* cleanup after the thead and close the thread handle */
}

Definition at line 193 of file qf.h.

QF_ACTIVE_SUPER_ QActive::super

base structure of QActive.

See also:
::QF_ACTIVE_SUPER_
Encapsulation and Single Inheritance in C

Definition at line 144 of file qf.h.

Referenced by QActive_start(), QF_run(), QK_sched_(), and QK_schedExt_().


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