QP/C++ 6.9.3
qequeue.hpp
Go to the documentation of this file.
1 
39 #ifndef QEQUEUE_HPP
40 #define QEQUEUE_HPP
41 
50 
51 #ifndef QF_EQUEUE_CTR_SIZE
52 
60  #define QF_EQUEUE_CTR_SIZE 1U
61 #endif
62 
63 
64 namespace QP {
65 
66 #if (QF_EQUEUE_CTR_SIZE == 1U)
73 #elif (QF_EQUEUE_CTR_SIZE == 2U)
74  using QEQueueCtr = std::uint16_t;
75 #elif (QF_EQUEUE_CTR_SIZE == 4U)
76  using QEQueueCtr = std::uint32_t;
77 #else
78  #error "QF_EQUEUE_CTR_SIZE defined incorrectly, expected 1U, 2U, or 4U"
79 #endif
80 
81 
82 //****************************************************************************
123 class QEQueue {
124 private:
125 
136  QEvt const * volatile m_frontEvt;
137 
139  QEvt const **m_ring;
140 
143 
145  QEQueueCtr volatile m_head;
146 
148  QEQueueCtr volatile m_tail;
149 
151  QEQueueCtr volatile m_nFree;
152 
158 
159 public:
161  QEQueue(void) noexcept;
162 
171  void init(QEvt const *qSto[], std::uint_fast16_t const qLen) noexcept;
172 
187  bool post(QEvt const * const e, std::uint_fast16_t const margin,
188  std::uint_fast8_t const qs_id) noexcept;
189 
198  void postLIFO(QEvt const * const e,
199  std::uint_fast8_t const qs_id) noexcept;
200 
213  QEvt const *get(std::uint_fast8_t const qs_id) noexcept;
214 
225  QEQueueCtr getNFree(void) const noexcept {
226  return m_nFree;
227  }
228 
240  QEQueueCtr getNMin(void) const noexcept {
241  return m_nMin;
242  }
243 
254  bool isEmpty(void) const noexcept {
255  return m_frontEvt == nullptr;
256  }
257 
258 private:
260  QEQueue(QEQueue const &) = delete;
261 
263  QEQueue & operator=(QEQueue const &) = delete;
264 
265  friend class QF;
266  friend class QActive;
267  friend class QXThread;
268  friend class QTicker;
269  friend class QS;
270 };
271 
272 } // namespace QP
273 
274 #endif // QEQUEUE_HPP
275 
unsigned int uint16_t
exact-width 16-bit unsigned int
Definition: 16bit/stdint.h:30
unsigned int uint_fast16_t
fast at-least 16-bit unsigned int
Definition: 16bit/stdint.h:38
unsigned long int uint32_t
exact-width 32-bit unsigned int
Definition: 16bit/stdint.h:31
unsigned char uint8_t
exact-width 8-bit unsigned int
Definition: 16bit/stdint.h:29
unsigned int uint_fast8_t
fast at-least 8-bit unsigned int
Definition: 16bit/stdint.h:36
QActive active object (based on QP::QHsm implementation)
Definition: qf.hpp:144
Native QF Event Queue class.
Definition: qequeue.hpp:123
QEQueueCtr volatile m_head
offset to where next event will be inserted into the buffer
Definition: qequeue.hpp:145
QEQueueCtr getNFree(void) const noexcept
"raw" thread-safe QF event queue operation for obtaining the number of free entries still available i...
Definition: qequeue.hpp:225
bool isEmpty(void) const noexcept
"raw" thread-safe QF event queue operation to find out if the queue is empty
Definition: qequeue.hpp:254
QEQueue & operator=(QEQueue const &)=delete
disallow assignment of QEQueue
QEvt const *volatile m_frontEvt
pointer to event at the front of the queue
Definition: qequeue.hpp:136
QEQueue(QEQueue const &)=delete
disallow copying of QEQueue
QEQueueCtr getNMin(void) const noexcept
"raw" thread-safe QF event queue operation for obtaining the minimum number of free entries ever in t...
Definition: qequeue.hpp:240
QEvt const * get(std::uint_fast8_t const qs_id) noexcept
"raw" thread-safe QF event queue implementation for the Last-In-First-Out (LIFO) event posting.
Definition: qf_qeq.cpp:287
void init(QEvt const *qSto[], std::uint_fast16_t const qLen) noexcept
Initializes the native QF event queue.
Definition: qf_qeq.cpp:84
QEvt const ** m_ring
pointer to the start of the ring buffer
Definition: qequeue.hpp:139
void postLIFO(QEvt const *const e, std::uint_fast8_t const qs_id) noexcept
"raw" thread-safe QF event queue implementation for the First-In-First-Out (FIFO) event posting....
Definition: qf_qeq.cpp:221
QEQueueCtr m_nMin
minimum number of free events ever in the ring buffer.
Definition: qequeue.hpp:157
bool post(QEvt const *const e, std::uint_fast16_t const margin, std::uint_fast8_t const qs_id) noexcept
"raw" thread-safe QF event queue implementation for the event posting (FIFO). You can call this funct...
Definition: qf_qeq.cpp:122
QEQueue(void) noexcept
public default constructor
Definition: qf_qeq.cpp:58
QEQueueCtr volatile m_tail
offset of where next event will be extracted from the buffer
Definition: qequeue.hpp:148
QEQueueCtr m_end
offset of the end of the ring buffer from the start of the buffer
Definition: qequeue.hpp:142
QEQueueCtr volatile m_nFree
number of free events in the ring buffer
Definition: qequeue.hpp:151
QF services.
Definition: qf.hpp:496
QS logging facilities.
Definition: qs.hpp:302
Ticker Active Object class.
Definition: qf.hpp:640
Extended (blocking) thread of the QXK preemptive kernel.
Definition: qxthread.hpp:66
namespace associated with the QP/C++ framework
Definition: struct.dox:1
std::uint8_t QEQueueCtr
The data type to store the ring-buffer counters based on the macro QF_EQUEUE_CTR_SIZE.
Definition: qequeue.hpp:72
QEvt base class.
Definition: qep.hpp:209