|
QP/C
|
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. | |
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.
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;
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.
Definition at line 182 of file qf.h.
Referenced by QActive_start(), QF_add_(), and QF_remove_().
| uint8_t QActive::running |
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 */ }
| QF_ACTIVE_SUPER_ QActive::super |
base structure of QActive.
Definition at line 144 of file qf.h.
Referenced by QActive_start(), QF_run(), QK_sched_(), and QK_schedExt_().
1.7.6.1