Native QP event queue. More...
#include "qequeue.hpp"
Public Member Functions | |
QEQueue () noexcept | |
void | init (QEvt const *qSto[], std::uint_fast16_t const qLen) noexcept |
bool | post (QEvt const *const e, std::uint_fast16_t const margin, std::uint_fast8_t const qsId) noexcept |
void | postLIFO (QEvt const *const e, std::uint_fast8_t const qsId) noexcept |
QEvt const * | get (std::uint_fast8_t const qsId) noexcept |
QEQueueCtr | getNFree () const noexcept |
QEQueueCtr | getNMin () const noexcept |
bool | isEmpty () const noexcept |
Private Member Functions | |
QEQueue (QEQueue const &other)=delete | |
QEQueue & | operator= (QEQueue const &other)=delete |
Private Attributes | |
QEvt const *volatile | m_frontEvt |
QEvt const ** | m_ring |
QEQueueCtr | m_end |
QEQueueCtr volatile | m_head |
QEQueueCtr volatile | m_tail |
QEQueueCtr volatile | m_nFree |
QEQueueCtr | m_nMin |
Friends | |
class | QActive |
class | QTicker |
class | QXMutex |
class | QXThread |
Native QP event queue.
This class describes the native QP 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 QP::QEQueue in the specific QF port header file.
The QP::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 QP::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_(). Additionally the function QEQueue_init() is used to initialize the queue.
The other set of functions, uses QP::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.
Definition at line 70 of file qequeue.hpp.
|
inlinenoexcept |
Default constructor of QP::QEQueue
Definition at line 87 of file qequeue.hpp.
|
privatedelete |
|
noexcept |
Initialize the native QF event queue.
Initialize the event queue by giving it the storage for the ring buffer.
[in] | qSto | an array of pointers to QP::QEvt to sereve as the ring buffer for the event queue |
[in] | qLen | the length of the qSto buffer (in QP::QEvt pointers) |
Definition at line 71 of file qf_qeq.cpp.
|
noexcept |
Post an event to the "raw" thread-safe event queue (FIFO).
Post an event to the "raw" thread-safe event queue using the First-In-First-Out (FIFO) order.
[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 this function will assert if posting |
[in] | qsId | QS-id of this state machine (for QS local filter) |
qf_qeq:200
margin
parameter 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.Definition at line 98 of file qf_qeq.cpp.
|
noexcept |
Post an event to the "raw" thread-safe event queue (LIFO).
Post an event to the "raw" thread-safe event queue using the Last-In-First-Out (LIFO) order.
[in] | e | pointer to the event to be posted to the queue |
[in] | qsId | QS-id of this state machine (for QS local filter) |
qf_qeq:300
Definition at line 178 of file qf_qeq.cpp.
|
noexcept |
Obtain an event from the "raw" thread-safe queue.
Retrieves an event from the front of the "raw" thread-safe queue and returns a pointer to this event to the caller.
[in] | qsId | QS-id of this state machine (for QS local filter) |
Definition at line 230 of file qf_qeq.cpp.
|
inlinenoexcept |
Obtain the number of free entries still available in the queue.
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.
Definition at line 107 of file qequeue.hpp.
|
inlinenoexcept |
Obtain the minimum number of free entries ever in the queue (a.k.a. "low-watermark").
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.
Definition at line 110 of file qequeue.hpp.
|
inlinenoexcept |
Find out if the queue is empty.
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.
Definition at line 113 of file qequeue.hpp.
|
friend |
Definition at line 81 of file qequeue.hpp.
|
friend |
Definition at line 82 of file qequeue.hpp.
|
friend |
Definition at line 83 of file qequeue.hpp.
|
friend |
Definition at line 84 of file qequeue.hpp.
|
private |
Pointer to event at the front of the queue.
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 to bypass the ring buffer altogether, greatly 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.
Definition at line 72 of file qequeue.hpp.
|
private |
Pointer to the start of the ring buffer
Definition at line 73 of file qequeue.hpp.
|
private |
Offset of the end of the ring buffer from the start of the buffer
Definition at line 74 of file qequeue.hpp.
|
private |
Offset to where next event will be inserted into the buffer
Definition at line 75 of file qequeue.hpp.
|
private |
Offset of where next event will be extracted from the buffer
Definition at line 76 of file qequeue.hpp.
|
private |
Number of free events in the ring buffer
Definition at line 77 of file qequeue.hpp.
|
private |
Minimum number of free events ever in the ring buffer.
This attribute remembers the low-watermark of the ring buffer, which provides a valuable information for sizing event queues.
Definition at line 78 of file qequeue.hpp.