QP/C++  7.0.1
Real-Time Embedded Framework
qequeue.hpp
Go to the documentation of this file.
1//============================================================================
2// QP/C++ Real-Time Embedded Framework (RTEF)
3// Copyright (C) 2005 Quantum Leaps, LLC. All rights reserved.
4//
5// SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-QL-commercial
6//
7// This software is dual-licensed under the terms of the open source GNU
8// General Public License version 3 (or any later version), or alternatively,
9// under the terms of one of the closed source Quantum Leaps commercial
10// licenses.
11//
12// The terms of the open source GNU General Public License version 3
13// can be found at: <www.gnu.org/licenses/gpl-3.0>
14//
15// The terms of the closed source Quantum Leaps commercial licenses
16// can be found at: <www.state-machine.com/licensing>
17//
18// Redistributions in source code must retain this top-level comment block.
19// Plagiarizing this software to sidestep the license obligations is illegal.
20//
21// Contact information:
22// <www.state-machine.com>
23// <info@state-machine.com>
24//============================================================================
30
31#ifndef QEQUEUE_HPP
32#define QEQUEUE_HPP
33
42
43#ifndef QF_EQUEUE_CTR_SIZE
44
52 #define QF_EQUEUE_CTR_SIZE 1U
53#endif
54
55namespace QP {
56
57#if (QF_EQUEUE_CTR_SIZE == 1U)
63 using QEQueueCtr = std::uint8_t;
64#elif (QF_EQUEUE_CTR_SIZE == 2U)
65 using QEQueueCtr = std::uint16_t;
66#elif (QF_EQUEUE_CTR_SIZE == 4U)
67 using QEQueueCtr = std::uint32_t;
68#else
69 #error "QF_EQUEUE_CTR_SIZE defined incorrectly, expected 1U, 2U, or 4U"
70#endif
71
72//============================================================================
113class QEQueue {
114private:
115
126 QEvt const * volatile m_frontEvt;
127
129 QEvt const **m_ring;
130
133
136
139
142
148
149public:
151 QEQueue(void) noexcept;
152
161 void init(QEvt const *qSto[], std::uint_fast16_t const qLen) noexcept;
162
177 bool post(QEvt const * const e, std::uint_fast16_t const margin,
178 std::uint_fast8_t const qs_id) noexcept;
179
188 void postLIFO(QEvt const * const e,
189 std::uint_fast8_t const qs_id) noexcept;
190
203 QEvt const *get(std::uint_fast8_t const qs_id) noexcept;
204
215 QEQueueCtr getNFree(void) const noexcept {
216 return m_nFree;
217 }
218
230 QEQueueCtr getNMin(void) const noexcept {
231 return m_nMin;
232 }
233
244 bool isEmpty(void) const noexcept {
245 return m_frontEvt == nullptr;
246 }
247
248private:
250 QEQueue(QEQueue const &) = delete;
251
253 QEQueue & operator=(QEQueue const &) = delete;
254
255 friend class QF;
256 friend class QActive;
257 friend class QXThread;
258 friend class QTicker;
259 friend class QS;
260};
261
262} // namespace QP
263
264#endif // QEQUEUE_HPP
QActive active object (based on QP::QHsm implementation)
Definition: qf.hpp:136
Native QF Event Queue class.
Definition: qequeue.hpp:113
QEQueueCtr volatile m_head
offset to where next event will be inserted into the buffer
Definition: qequeue.hpp:135
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:215
bool isEmpty(void) const noexcept
"raw" thread-safe QF event queue operation to find out if the queue is empty
Definition: qequeue.hpp:244
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:126
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:230
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:281
void init(QEvt const *qSto[], std::uint_fast16_t const qLen) noexcept
Initializes the native QF event queue.
Definition: qf_qeq.cpp:81
QEvt const ** m_ring
pointer to the start of the ring buffer
Definition: qequeue.hpp:129
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:217
QEQueueCtr m_nMin
minimum number of free events ever in the ring buffer.
Definition: qequeue.hpp:147
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).
Definition: qf_qeq.cpp:119
QEQueue(void) noexcept
public default constructor
Definition: qf_qeq.cpp:55
QEQueueCtr volatile m_tail
offset of where next event will be extracted from the buffer
Definition: qequeue.hpp:138
QEQueueCtr m_end
offset of the end of the ring buffer from the start of the buffer
Definition: qequeue.hpp:132
QEQueueCtr volatile m_nFree
number of free events in the ring buffer
Definition: qequeue.hpp:141
QF services.
Definition: qf.hpp:487
QS software tracing facilities.
Definition: qs.hpp:260
"Ticker" Active Object class
Definition: qf.hpp:635
Extended (blocking) thread of the QXK preemptive kernel.
Definition: qxthread.hpp:58
namespace associated with the QP/C++ framework
Definition: exa_native.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:63
QEvt base class.
Definition: qep.hpp:191