QP/C++  8.0.0
Real-Time Embedded Framework
Loading...
Searching...
No Matches
qmpool.hpp
Go to the documentation of this file.
1//$file${include::qmpool.hpp} vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
2//
3// Model: qpcpp.qm
4// File: ${include::qmpool.hpp}
5//
6// This code has been generated by QM 7.0.0 <www.state-machine.com/qm>.
7// DO NOT EDIT THIS FILE MANUALLY. All your changes will be lost.
8//
9// Copyright (C) 2005 Quantum Leaps, LLC. All rights reserved.
10//
11// Q u a n t u m L e a P s
12// ------------------------
13// Modern Embedded Software
14//
15// SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-QL-commercial
16//
17// The QP/C++ software is dual-licensed under the terms of the open-source
18// GNU General Public License (GPL) or under the terms of one of the closed-
19// source Quantum Leaps commercial licenses.
20//
21// Redistributions in source code must retain this top-level comment block.
22// Plagiarizing this software to sidestep the license obligations is illegal.
23//
24// NOTE:
25// The GPL does NOT permit the incorporation of this code into proprietary
26// programs. Please contact Quantum Leaps for commercial licensing options,
27// which expressly supersede the GPL and are designed explicitly for
28// closed-source distribution.
29//
30// Quantum Leaps contact information:
31// <www.state-machine.com/licensing>
32// <info@state-machine.com>
33//
34//$endhead${include::qmpool.hpp} ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
35#ifndef QMPOOL_HPP_
36#define QMPOOL_HPP_
37
38#ifndef QF_MPOOL_SIZ_SIZE
39 #define QF_MPOOL_SIZ_SIZE 2U
40#endif
41#ifndef QF_MPOOL_CTR_SIZE
42 #define QF_MPOOL_CTR_SIZE 2U
43#endif
44
45namespace QP {
46
47#if (QF_MPOOL_SIZ_SIZE == 1U)
48 using QMPoolSize = std::uint8_t;
49#elif (QF_MPOOL_SIZ_SIZE == 2U)
50 using QMPoolSize = std::uint16_t;
51#elif (QF_MPOOL_SIZ_SIZE == 4U)
52 using QMPoolSize = std::uint32_t;
53#else
54 #error "QF_MPOOL_SIZ_SIZE defined incorrectly, expected 1U, 2U, or 4U"
55#endif
56
57#if (QF_MPOOL_CTR_SIZE == 1U)
58 using QMPoolCtr = std::uint8_t;
59#elif (QF_MPOOL_CTR_SIZE == 2U)
60 using QMPoolCtr = std::uint16_t;
61#elif (QF_MPOOL_CTR_SIZE == 4U)
62 using QMPoolCtr = std::uint32_t;
63#else
64 #error "QF_MPOOL_CTR_SIZE defined incorrectly, expected 1U, 2U, or 4U"
65#endif
66
67} // namespace QP
68
69#define QF_MPOOL_EL(evType_) struct { \
70 QP::QFreeBlock sto_[((sizeof(evType_) - 1U) / (2U * sizeof(void *))) + 1U]; \
71}
72
73//$declare${QF::QFreeBlock} vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
74namespace QP {
75
76//${QF::QFreeBlock} ..........................................................
78private:
80
81#ifndef Q_UNSAFE
82 std::uintptr_t m_next_dis;
83#endif // ndef Q_UNSAFE
84 friend class QMPool;
85}; // class QFreeBlock
86
87} // namespace QP
88//$enddecl${QF::QFreeBlock} ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
89
90//$declare${QF::QMPool} vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
91namespace QP {
92
93//${QF::QMPool} ..............................................................
94class QMPool {
95private:
102
103#ifndef Q_UNSAFE
105#endif // ndef Q_UNSAFE
106
107#ifndef Q_UNSAFE
108 std::uintptr_t m_free_head_dis;
109#endif // ndef Q_UNSAFE
110
111#ifndef Q_UNSAFE
113#endif // ndef Q_UNSAFE
114
115public:
117 : m_start(nullptr),
118 m_end(nullptr),
119 m_free_head(nullptr),
120 m_blockSize(0U),
121 m_nTot(0U),
122 m_nFree(0U)
123 #ifndef Q_UNSAFE
124 ,m_nMin(0U),
125 m_free_head_dis(static_cast<std::uintptr_t>(~0U)),
126 m_nFree_dis(static_cast<QEQueueCtr>(~0U))
127 #endif
128 {}
129 void init(
130 void * const poolSto,
131 std::uint_fast32_t const poolSize,
132 std::uint_fast16_t const blockSize) noexcept;
133 void * get(
134 std::uint_fast16_t const margin,
135 std::uint_fast8_t const qsId) noexcept;
136 void put(
137 void * const block,
138 std::uint_fast8_t const qsId) noexcept;
139 QMPoolSize getBlockSize() const noexcept;
140 QMPoolCtr getNMin() const noexcept {
141 #ifndef Q_UNSAFE
142 return m_nMin;
143 #else
144 return 0U;
145 #endif
146 }
147 QMPoolCtr getNFree() const noexcept {
148 return m_nFree;
149 }
150
151private:
152 QMPool(QEQueue const & other) = delete;
153 QMPool & operator=(QMPool const & other) = delete;
154
155public:
156
157#ifdef QF_ISR_API
159 std::uint_fast16_t const margin,
160 std::uint_fast8_t const qsId) noexcept;
161#endif // def QF_ISR_API
162
163#ifdef QF_ISR_API
165 void * const b,
166 std::uint_fast8_t const qsId) noexcept;
167#endif // def QF_ISR_API
168}; // class QMPool
169
170} // namespace QP
171//$enddecl${QF::QMPool} ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
172
173#endif // QMPOOL_HPP_
Native QP event queue.
Definition qequeue.hpp:60
Structure representing a free block in QP::QMPool.
Definition qmpool.hpp:77
QFreeBlock * m_next
Definition qmpool.hpp:79
std::uintptr_t m_next_dis
Definition qmpool.hpp:82
Native QF Memory Pool.
Definition qmpool.hpp:94
void * get(std::uint_fast16_t const margin, std::uint_fast8_t const qsId) noexcept
Definition qf_mem.cpp:136
QMPool & operator=(QMPool const &other)=delete
QMPool(QEQueue const &other)=delete
QMPoolCtr volatile m_nFree
Definition qmpool.hpp:101
QMPoolCtr getNFree() const noexcept
Definition qmpool.hpp:147
void init(void *const poolSto, std::uint_fast32_t const poolSize, std::uint_fast16_t const blockSize) noexcept
Definition qf_mem.cpp:63
QFreeBlock * m_start
Definition qmpool.hpp:96
QMPoolSize m_blockSize
Definition qmpool.hpp:99
QFreeBlock * m_end
Definition qmpool.hpp:97
QMPoolSize getBlockSize() const noexcept
Definition qf_mem.cpp:286
QFreeBlock *volatile m_free_head
Definition qmpool.hpp:98
std::uintptr_t m_free_head_dis
Definition qmpool.hpp:108
void putFromISR(void *const b, std::uint_fast8_t const qsId) noexcept
void put(void *const block, std::uint_fast8_t const qsId) noexcept
Definition qf_mem.cpp:233
void * getFromISR(std::uint_fast16_t const margin, std::uint_fast8_t const qsId) noexcept
QMPoolCtr m_nMin
Definition qmpool.hpp:104
QMPoolCtr m_nFree_dis
Definition qmpool.hpp:112
QMPoolCtr m_nTot
Definition qmpool.hpp:100
QMPoolCtr getNMin() const noexcept
Definition qmpool.hpp:140
QP/C++ framework.
Definition qequeue.hpp:42
std::uint16_t QMPoolSize
Definition qmpool.hpp:50
std::uint16_t QMPoolCtr
Definition qmpool.hpp:60
std::uint16_t QEQueueCtr
Definition qequeue.hpp:47
#define Q_UNSAFE
Disable the QP Functional Safety (FuSa) Subsystem.
Definition qp_config.hpp:91