QP/C++ 8.1.4
Real-Time Event Framework
Loading...
Searching...
No Matches
qequeue.hpp
Go to the documentation of this file.
1//============================================================================
2// QP/C++ Real-Time Event Framework (RTEF)
3//
4// Copyright (C) 2005 Quantum Leaps, LLC. All rights reserved.
5//
6// Q u a n t u m L e a P s
7// ------------------------
8// Modern Embedded Software
9//
10// SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-QL-commercial
11//
12// This software is dual-licensed under the terms of the open-source GNU
13// General Public License (GPL) or under the terms of one of the closed-
14// source Quantum Leaps commercial licenses.
15//
16// Redistributions in source code must retain this top-level comment block.
17// Plagiarizing this software to sidestep the license obligations is illegal.
18//
19// NOTE:
20// The GPL does NOT permit the incorporation of this code into proprietary
21// programs. Please contact Quantum Leaps for commercial licensing options,
22// which expressly supersede the GPL and are designed explicitly for
23// closed-source distribution.
24//
25// Quantum Leaps contact information:
26// <www.state-machine.com/licensing>
27// <info@state-machine.com>
28//============================================================================
29#ifndef QEQUEUE_HPP_
30#define QEQUEUE_HPP_
31
32#ifndef QF_EQUEUE_CTR_SIZE
33 #define QF_EQUEUE_CTR_SIZE 1U
34#endif
35
36namespace QP {
37
38#if (QF_EQUEUE_CTR_SIZE == 1U)
39 using QEQueueCtr = std::uint8_t;
40#elif (QF_EQUEUE_CTR_SIZE == 2U)
41 using QEQueueCtr = std::uint16_t;
42#else
43 #error QF_EQUEUE_CTR_SIZE defined incorrectly, expected 1U or 2U
44#endif
45
46// forward declarations (NOTE must be consistent with "qp.hpp")
47class QEvt;
48
49//----------------------------------------------------------------------------
50// NOTE must be consistent with "qp.hpp"
51struct QEvtPtr {
52 QEvt const *e;
53};
54
55//----------------------------------------------------------------------------
56class QEQueue {
57public:
58 QEQueue() noexcept;
59 void init(
60 QEvtPtr * const qSto,
61 std::uint_fast16_t const qLen) noexcept;
62 bool post(
63 QEvt const * const e,
64 std::uint_fast16_t const margin,
65 std::uint_fast8_t const qsId) noexcept;
66 void postLIFO(
67 QEvt const * const e,
68 std::uint_fast8_t const qsId) noexcept;
69 QEvt const * get(std::uint_fast8_t const qsId) noexcept;
70 std::uint16_t getFree() const noexcept;
71 std::uint16_t getUse() const noexcept;
72 std::uint16_t getMin() const noexcept;
73 bool isEmpty() const noexcept;
74 QEvt const *peekFront() const &;
75 QEvt const *peekFront() &&
76 // ref-qualified reference (MISRA-C++:2023 Rule 6.8.4)
77 = delete;
78
79private:
87
89 QEvt const * const e,
90 void const * const sender);
91
92 // friends...
93 friend class QActive;
94 friend class QTicker;
95 friend class QXMutex;
96 friend class QXThread;
97 friend class QS;
98}; // class QEQueue
99
100} // namespace QP
101
102#endif // QEQUEUE_HPP_
friend class QTicker
Definition qequeue.hpp:94
friend class QXMutex
Definition qequeue.hpp:95
QEvtPtr * m_ring
Pointer to the start of the ring buffer.
Definition qequeue.hpp:81
friend class QActive
Definition qequeue.hpp:93
friend class QS
Definition qequeue.hpp:97
std::uint16_t getUse() const noexcept
Obtain the number of entries in use in the queue.
Definition qf_qeq.cpp:282
QEQueueCtr m_nFree
Number of free events in the ring buffer.
Definition qequeue.hpp:85
QEQueue() noexcept
Default constructor of QP::QEQueue.
Definition qf_qeq.cpp:48
void postFIFO_(QEvt const *const e, void const *const sender)
void init(QEvtPtr *const qSto, std::uint_fast16_t const qLen) noexcept
Initialize the native QF event queue.
Definition qf_qeq.cpp:58
QEvt const * get(std::uint_fast8_t const qsId) noexcept
Obtain an event from the "raw" thread-safe queue.
Definition qf_qeq.cpp:220
QEvt const * peekFront() const &
Definition qf_qeq.cpp:312
bool isEmpty() const noexcept
Find out if the queue is empty.
Definition qf_qeq.cpp:306
QEQueueCtr m_nMin
Minimum number of free events ever in the ring buffer.
Definition qequeue.hpp:86
std::uint16_t getMin() const noexcept
Obtain the minimum number of free entries ever in the queue (a.k.a. "low-watermark").
Definition qf_qeq.cpp:300
bool post(QEvt const *const e, std::uint_fast16_t const margin, std::uint_fast8_t const qsId) noexcept
Post an event to the "raw" thread-safe event queue (FIFO).
Definition qf_qeq.cpp:84
QEvtPtr m_frontEvt
Pointer to event at the front of the queue.
Definition qequeue.hpp:80
QEQueueCtr m_head
Offset to where next event will be inserted into the buffer.
Definition qequeue.hpp:83
std::uint16_t getFree() const noexcept
Obtain the number of free entries still available in the queue.
Definition qf_qeq.cpp:294
QEvt const * peekFront() &&=delete
QEQueueCtr m_end
Offset of the end of the ring buffer from the start of the buffer.
Definition qequeue.hpp:82
void postLIFO(QEvt const *const e, std::uint_fast8_t const qsId) noexcept
Post an event to the "raw" thread-safe event queue (LIFO).
Definition qf_qeq.cpp:164
friend class QXThread
Definition qequeue.hpp:96
QEQueueCtr m_tail
Offset of where next event will be extracted from the buffer.
Definition qequeue.hpp:84
Event class.
Definition qp.hpp:101
QP/C++ Framework namespace.
Definition qequeue.hpp:36
std::uint16_t QEQueueCtr
The data type to store the ring-buffer counters.
Definition qequeue.hpp:41
QEvt const * e
Definition qequeue.hpp:52