QP/C++  8.0.3
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 {
54private:
55 QEvt const * volatile m_frontEvt;
56 QEvt const * * m_ring;
62
63 // friends...
64 friend class QActive;
65 friend class QTicker;
66 friend class QXMutex;
67 friend class QXThread;
68
69public:
70 QEQueue() noexcept
71 : m_frontEvt(nullptr),
72 m_ring(nullptr),
73 m_end(0U),
74 m_head(0U),
75 m_tail(0U),
76 m_nFree(0U),
77 m_nMin(0U)
78 {}
79 void init(
80 QEvt const * * const qSto,
81 std::uint_fast16_t const qLen) noexcept;
82 bool post(
83 QEvt const * const e,
84 std::uint_fast16_t const margin,
85 std::uint_fast8_t const qsId) noexcept;
86 void postLIFO(
87 QEvt const * const e,
88 std::uint_fast8_t const qsId) noexcept;
89 QEvt const * get(std::uint_fast8_t const qsId) noexcept;
90 QEQueueCtr getNFree() const noexcept {
91 return m_nFree;
92 }
93 QEQueueCtr getNMin() const noexcept {
94 return m_nMin;
95 }
96 bool isEmpty() const noexcept {
97 return m_frontEvt == nullptr;
98 }
99
100private:
101 QEQueue(QEQueue const & other) = delete;
102 QEQueue & operator=(QEQueue const & other) = delete;
104 QEvt const * const e,
105 void const * const sender);
106}; // class QEQueue
107
108} // namespace QP
109
110#endif // QEQUEUE_HPP_
friend class QTicker
Definition qequeue.hpp:65
friend class QXMutex
Definition qequeue.hpp:66
friend class QActive
Definition qequeue.hpp:64
QEQueueCtr volatile m_nFree
Definition qequeue.hpp:60
QEQueue() noexcept
Definition qequeue.hpp:70
void postFIFO_(QEvt const *const e, void const *const sender)
QEvt const * get(std::uint_fast8_t const qsId) noexcept
Definition qf_qeq.cpp:210
QEQueue & operator=(QEQueue const &other)=delete
bool isEmpty() const noexcept
Definition qequeue.hpp:96
QEQueueCtr volatile m_tail
Definition qequeue.hpp:59
QEvt const ** m_ring
Definition qequeue.hpp:56
void init(QEvt const **const qSto, std::uint_fast16_t const qLen) noexcept
Definition qf_qeq.cpp:48
QEQueueCtr m_nMin
Definition qequeue.hpp:61
bool post(QEvt const *const e, std::uint_fast16_t const margin, std::uint_fast8_t const qsId) noexcept
Definition qf_qeq.cpp:73
QEQueueCtr getNFree() const noexcept
Definition qequeue.hpp:90
QEQueueCtr volatile m_head
Definition qequeue.hpp:58
QEQueue(QEQueue const &other)=delete
QEQueueCtr getNMin() const noexcept
Definition qequeue.hpp:93
QEvt const *volatile m_frontEvt
Definition qequeue.hpp:55
QEQueueCtr m_end
Definition qequeue.hpp:57
void postLIFO(QEvt const *const e, std::uint_fast8_t const qsId) noexcept
Definition qf_qeq.cpp:154
friend class QXThread
Definition qequeue.hpp:67
Event class.
Definition qp.hpp:115
QP/C++ framework.
Definition qequeue.hpp:36
std::uint16_t QEQueueCtr
Definition qequeue.hpp:41