Native QF Event Queue. More...
Public Member Functions | |
| void | QEQueue_init (QEQueue *const me, QEvtPtr *const qSto, uint_fast16_t const qLen) |
| Initialize the native QF event queue. | |
| bool | QEQueue_post (QEQueue *const me, struct QEvt const *const e, uint_fast16_t const margin, uint_fast8_t const qsId) |
| Post an event to the "raw" thread-safe event queue (FIFO). | |
| void | QEQueue_postLIFO (QEQueue *const me, struct QEvt const *const e, uint_fast8_t const qsId) |
| Post an event to the "raw" thread-safe event queue (LIFO). | |
| struct QEvt const * | QEQueue_get (QEQueue *const me, uint_fast8_t const qsId) |
| Obtain an event from the "raw" thread-safe queue. | |
| uint16_t | QEQueue_getFree (QEQueue const *const me) |
| Obtain the number of free entries still available in the queue. | |
| uint16_t | QEQueue_getUse (QEQueue const *const me) |
| Obtain the number of entries in use in the queue. | |
| uint16_t | QEQueue_getMin (QEQueue const *const me) |
| Obtain the minimum number of free entries ever in the queue (a.k.a. "low-watermark"). | |
| bool | QEQueue_isEmpty (QEQueue const *const me) |
| Find out if the queue is empty. | |
Private Attributes | |
| QEvtPtr | frontEvt |
| Pointer to event at the front of the queue. | |
| QEvtPtr * | ring |
| Pointer to the start of the ring buffer . | |
| QEQueueCtr | end |
| Offset of the end of the ring buffer from the start of the buffer . | |
| QEQueueCtr | head |
| Offset to where next event will be inserted into the buffer . | |
| QEQueueCtr | tail |
| Offset of where next event will be extracted from the buffer . | |
| QEQueueCtr | nFree |
| Number of free entries in the ring buffer plus the front-event entry . | |
| QEQueueCtr | nMin |
| Minimum number of free entries ever in the ring buffer plus the front-event entry. | |
Native QF Event Queue.
Details
This class describes the native QF event queue, which can be used as the event queue for active objects, or as a simple "raw" event queue for thread-safe event passing among non-framework entities, such as ISRs, device drivers, or other third-party components.
The native QF event queue is configured by defining the macro QACTIVE_EQUEUE_TYPE as QEQueue in the specific QF port header file.
The QEQueue structure contains only data members for managing an event queue, but does not contain the storage for the queue buffer, which must be provided externally during the queue initialization.
The event queue can store only event pointers, not the whole events. The internal implementation uses the standard ring-buffer plus one external location that optimizes the queue operation for the most frequent case of empty queue.
The QEQueue structure is used with two sets of functions. One set is for the active object event queue, which might need to block the active object task when the event queue is empty and might need to unblock it when events are posted to the queue. The interface for the native active object event queue consists of the following functions: QActive_post(), QActive_postLIFO(), and QActive_get_().
The other set of functions uses QEQueue as a simple "raw" event queue to pass events between entities other than active objects, such as ISRs. The "raw" event queue is not capable of blocking on the get() operation, but is still thread-safe because it uses QF critical section to protect its integrity. The interface for the "raw" thread-safe queue consists of the following functions: QEQueue_post(), QEQueue_postLIFO(), and QEQueue_get(). Additionally the function QEQueue_init() is used to initialize the queue.
Most event queue operations (both the active object queues and the "raw" queues) internally use the QF critical section. You should be careful not to invoke those operations from other critical sections when nesting of critical sections is not supported.
See also
Backward Traceability
Forward Traceability
Initialize the native QF event queue.
Details
Initialize the event queue by giving it the storage for the ring buffer.
| [in,out] | me | instance pointer (see [SAS_QP_TECH_20]) |
| [in] | qSto | an array of QEvtPtr to serve as the ring buffer for the event queue (may be NULL only when qLen is 0) |
| [in] | qLen | the length of the qSto buffer (in QEvt pointers) |
Backward Traceability
Forward Traceability
| bool QEQueue_post | ( | QEQueue *const | me, |
| struct QEvt const *const | e, | ||
| uint_fast16_t const | margin, | ||
| uint_fast8_t const | qsId ) |
Post an event to the "raw" thread-safe event queue (FIFO).
Details
Post an event to the "raw" thread-safe event queue using the First-In-First-Out (FIFO) order.
| [in,out] | me | instance pointer (see [SAS_QP_TECH_20]) |
| [in] | e | pointer to the event to be posted to the queue |
| [in] | margin | number of required free slots in the queue after posting the event. The special value QF_NO_MARGIN means that the posting must succeed (an assertion fires otherwise). |
| [in] | qsId | QS-id of this state machine (for QS local filter) |
| true | (success) when the posting succeeded with the provided margin |
| false | (failure) when the posting fails. |
See also
Backward Traceability
Forward Traceability
Post an event to the "raw" thread-safe event queue (LIFO).
Details
Post an event to the "raw" thread-safe event queue using the Last-In-First-Out (LIFO) order.
| [in,out] | me | instance pointer (see [SAS_QP_TECH_20]) |
| [in] | e | pointer to the event to be posted to the queue |
| [in] | qsId | QS-id of this state machine (for QS local filter) |
See also
Backward Traceability
Forward Traceability
Obtain an event from the "raw" thread-safe queue.
Details
Retrieves an event from the front of the "raw" thread-safe queue and returns a pointer to this event to the caller.
| [in,out] | me | instance pointer (see [SAS_QP_TECH_20]) |
| [in] | qsId | QS-id of this state machine (for QS local filter) |
| pointer | pointer to event at the front of the queue, if the queue is not empty |
| NULL | if the queue is empty. |
See also
Backward Traceability
Forward Traceability
| uint16_t QEQueue_getFree | ( | QEQueue const *const | me | ) |
Obtain the number of free entries still available in the queue.
Details
This operation needs to be used with caution because the number of free entries can change unexpectedly. The main intent for using this operation is in conjunction with event deferral. In this case, the queue is accessed only from a single thread (by a single AO), so the number of free entries cannot change unexpectedly.
| [in] | me | instance pointer (see [SAS_QP_TECH_20]) |
| number | the current number of free slots in the queue. |
Forward Traceability
| uint16_t QEQueue_getUse | ( | QEQueue const *const | me | ) |
Obtain the number of entries in use in the queue.
Details
This operation needs to be used with caution because the number of entries in use can change unexpectedly. The main intent for using this operation is in conjunction with event deferral. In this case, the queue is accessed only from a single thread (by a single AO), so the number of free entries cannot change unexpectedly.
| [in] | me | instance pointer (see [SAS_QP_TECH_20]) |
| number | the current number of used slots in the queue. |
Forward Traceability
| uint16_t QEQueue_getMin | ( | QEQueue const *const | me | ) |
Obtain the minimum number of free entries ever in the queue (a.k.a. "low-watermark").
Details
This operation needs to be used with caution because the "low-watermark" can change unexpectedly. The main intent for using this operation is to get an idea of queue usage to size the queue adequately.
| [in] | me | instance pointer (see [SAS_QP_TECH_20]) |
| number | the minimum number of free entries ever in the queue since init. |
Backward Traceability
Forward Traceability
| bool QEQueue_isEmpty | ( | QEQueue const *const | me | ) |
Find out if the queue is empty.
Details
This operation needs to be used with caution because the queue status can change unexpectedly. The main intent for using this operation is in conjunction with event deferral. In this case, the queue is accessed only from a single thread (by a single AO), so no other entity can post events to the queue.
| [in,out] | me | instance pointer (see [SAS_QP_TECH_20]) |
| true | If the queue is currently empty |
| false | Otherwise |
Forward Traceability
|
private |
Pointer to event at the front of the queue.
Details
All incoming and outgoing events pass through the frontEvt location. When the queue is empty (which is most of the time), the extra frontEvt location allows bypassing the ring buffer altogether, significantly optimizing the performance of the queue. Only bursts of events engage the ring buffer.
The additional role of this attribute is to indicate the empty status of the queue. The queue is empty when frontEvt is NULL.
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
Minimum number of free entries ever in the ring buffer plus the front-event entry.
Details
This attribute remembers the low-watermark of the ring buffer, which provides valuable information for sizing event queues.
See also