QP/C++ 8.1.1
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
46class QEvt; // forward declaration
47
48} // namespace QP
49
50//============================================================================
51namespace QP {
52
53class QEQueue {
54public:
55 QEQueue() noexcept;
56 void init(
57 QEvt const * * const qSto,
58 std::uint_fast16_t const qLen) noexcept;
59 bool post(
60 QEvt const * const e,
61 std::uint_fast16_t const margin,
62 std::uint_fast8_t const qsId) noexcept;
63 void postLIFO(
64 QEvt const * const e,
65 std::uint_fast8_t const qsId) noexcept;
66 QEvt const * get(std::uint_fast8_t const qsId) noexcept;
67 std::uint16_t getFree() const noexcept;
68 std::uint16_t getUse() const noexcept;
69 std::uint16_t getMin() const noexcept;
70 bool isEmpty() const noexcept;
71 QEvt const *peekFront() const &;
72 QEvt const *peekFront() &&
73 // ref-qualified reference (MISRA-C++:2023 Rule 6.8.4)
74 = delete;
75
76private:
78 QEvt const * * m_ring;
84
86 QEvt const * const e,
87 void const * const sender);
88
89 // friends...
90 friend class QActive;
91 friend class QTicker;
92 friend class QXMutex;
93 friend class QXThread;
94 friend class QS;
95}; // class QEQueue
96
97} // namespace QP
98
99#endif // QEQUEUE_HPP_
friend class QTicker
Definition qequeue.hpp:91
friend class QXMutex
Definition qequeue.hpp:92
friend class QActive
Definition qequeue.hpp:90
friend class QS
Definition qequeue.hpp:94
std::uint16_t getUse() const noexcept
Obtain the number of entries in use in the queue.
Definition qf_qeq.cpp:285
QEQueueCtr m_nFree
Number of free events in the ring buffer.
Definition qequeue.hpp:82
QEQueue() noexcept
Default constructor of QP::QEQueue.
Definition qf_qeq.cpp:48
void postFIFO_(QEvt const *const e, void const *const sender)
QEvt const * get(std::uint_fast8_t const qsId) noexcept
Obtain an event from the "raw" thread-safe queue.
Definition qf_qeq.cpp:223
QEvt const * peekFront() const &
Definition qf_qeq.cpp:315
bool isEmpty() const noexcept
Find out if the queue is empty.
Definition qf_qeq.cpp:309
QEvt const ** m_ring
Pointer to the start of the ring buffer.
Definition qequeue.hpp:78
void init(QEvt const **const qSto, std::uint_fast16_t const qLen) noexcept
Initialize the native QF event queue.
Definition qf_qeq.cpp:58
QEQueueCtr m_nMin
Minimum number of free events ever in the ring buffer.
Definition qequeue.hpp:83
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:303
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
QEvt const * m_frontEvt
Pointer to event at the front of the queue.
Definition qequeue.hpp:77
QEQueueCtr m_head
Offset to where next event will be inserted into the buffer.
Definition qequeue.hpp:80
std::uint16_t getFree() const noexcept
Obtain the number of free entries still available in the queue.
Definition qf_qeq.cpp:297
QEvt const * peekFront() &&=delete
QEQueueCtr m_end
Offset of the end of the ring buffer from the start of the buffer.
Definition qequeue.hpp:79
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:168
friend class QXThread
Definition qequeue.hpp:93
QEQueueCtr m_tail
Offset of where next event will be extracted from the buffer.
Definition qequeue.hpp:81
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