QP/C++  7.3.3
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 6.1.1 <www.state-machine.com/qm>.
7// DO NOT EDIT THIS FILE MANUALLY. All your changes will be lost.
8//
9// This code is covered by the following QP license:
10// License # : LicenseRef-QL-dual
11// Issued to : Any user of the QP/C++ real-time embedded framework
12// Framework(s) : qpcpp
13// Support ends : 2024-12-31
14// License scope:
15//
16// Copyright (C) 2005 Quantum Leaps, LLC <state-machine.com>.
17//
18// Q u a n t u m L e a P s
19// ------------------------
20// Modern Embedded Software
21//
22// SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-QL-commercial
23//
24// This software is dual-licensed under the terms of the open source GNU
25// General Public License version 3 (or any later version), or alternatively,
26// under the terms of one of the closed source Quantum Leaps commercial
27// licenses.
28//
29// The terms of the open source GNU General Public License version 3
30// can be found at: <www.gnu.org/licenses/gpl-3.0>
31//
32// The terms of the closed source Quantum Leaps commercial licenses
33// can be found at: <www.state-machine.com/licensing>
34//
35// Redistributions in source code must retain this top-level comment block.
36// Plagiarizing this software to sidestep the license obligations is illegal.
37//
38// Contact information:
39// <www.state-machine.com/licensing>
40// <info@state-machine.com>
41//
42//$endhead${include::qmpool.hpp} ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
43#ifndef QMPOOL_HPP_
44#define QMPOOL_HPP_
45
46#ifndef QF_MPOOL_SIZ_SIZE
47 #define QF_MPOOL_SIZ_SIZE 2U
48#endif
49#ifndef QF_MPOOL_CTR_SIZE
50 #define QF_MPOOL_CTR_SIZE 2U
51#endif
52
53namespace QP {
54
55#if (QF_MPOOL_SIZ_SIZE == 1U)
56 using QMPoolSize = std::uint8_t;
57#elif (QF_MPOOL_SIZ_SIZE == 2U)
58 using QMPoolSize = std::uint16_t;
59#elif (QF_MPOOL_SIZ_SIZE == 4U)
60 using QMPoolSize = std::uint32_t;
61#else
62 #error "QF_MPOOL_SIZ_SIZE defined incorrectly, expected 1U, 2U, or 4U"
63#endif
64
65#if (QF_MPOOL_CTR_SIZE == 1U)
66 using QMPoolCtr = std::uint8_t;
67#elif (QF_MPOOL_CTR_SIZE == 2U)
68 using QMPoolCtr = std::uint16_t;
69#elif (QF_MPOOL_CTR_SIZE == 4U)
70 using QMPoolCtr = std::uint32_t;
71#else
72 #error "QF_MPOOL_CTR_SIZE defined incorrectly, expected 1U, 2U, or 4U"
73#endif
74
75} // namespace QP
76
77#define QF_MPOOL_EL(evType_) struct { \
78 QP::QFreeBlock sto_[((sizeof(evType_) - 1U) \
79 / sizeof(QP::QFreeBlock)) + 1U]; }
80//$declare${QF::QFreeBlock} vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
81namespace QP {
82
83//${QF::QFreeBlock} ..........................................................
85private:
87
88#ifndef Q_UNSAFE
89 std::uintptr_t m_next_dis;
90#endif // ndef Q_UNSAFE
91 friend class QMPool;
92}; // class QFreeBlock
93
94} // namespace QP
95//$enddecl${QF::QFreeBlock} ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
96
97//$declare${QF::QMPool} vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
98namespace QP {
99
100//${QF::QMPool} ..............................................................
101class QMPool {
102private:
110
111public:
113 : m_start(nullptr),
114 m_end(nullptr),
115 m_free_head(nullptr),
116 m_blockSize(0U),
117 m_nTot(0U),
118 m_nFree(0U),
119 m_nMin(0U)
120 {}
121
122#ifdef Q_XTOR
123 ~QMPool();
124#endif // def Q_XTOR
125 void init(
126 void * const poolSto,
127 std::uint_fast32_t const poolSize,
128 std::uint_fast16_t const blockSize) noexcept;
129 void * get(
130 std::uint_fast16_t const margin,
131 std::uint_fast8_t const qsId) noexcept;
132 void put(
133 void * const block,
134 std::uint_fast8_t const qsId) noexcept;
135 QMPoolSize getBlockSize() const noexcept;
136 QMPoolCtr getNMin() const noexcept {
137 return m_nMin;
138 }
139 QMPoolCtr getNFree() const noexcept {
140 return m_nFree;
141 }
142
143private:
144 QMPool(QEQueue const & other) = delete;
145 QMPool & operator=(QMPool const & other) = delete;
146
147public:
148
149#ifdef QF_ISR_API
151 std::uint_fast16_t const margin,
152 std::uint_fast8_t const qsId) noexcept;
153#endif // def QF_ISR_API
154
155#ifdef QF_ISR_API
157 void * const b,
158 std::uint_fast8_t const qsId) noexcept;
159#endif // def QF_ISR_API
160}; // class QMPool
161
162} // namespace QP
163//$enddecl${QF::QMPool} ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
164
165#endif // QMPOOL_HPP_
Native QP event queue.
Definition qequeue.hpp:70
Structure representing a free block in QP::QMPool.
Definition qmpool.hpp:84
std::uintptr_t m_next_dis
Definition qmpool.hpp:89
QFreeBlock * m_next
Definition qmpool.hpp:86
Native QF Memory Pool.
Definition qmpool.hpp:101
void put(void *const block, std::uint_fast8_t const qsId) noexcept
Definition qf_mem.cpp:209
QFreeBlock * m_end
Definition qmpool.hpp:104
QMPool & operator=(QMPool const &other)=delete
QMPool(QEQueue const &other)=delete
QMPoolCtr m_nMin
Definition qmpool.hpp:109
QMPoolCtr volatile m_nFree
Definition qmpool.hpp:108
QMPoolCtr getNFree() const noexcept
Definition qmpool.hpp:139
QFreeBlock *volatile m_free_head
Definition qmpool.hpp:105
QMPoolSize getBlockSize() const noexcept
Definition qf_mem.cpp:248
QMPoolSize m_blockSize
Definition qmpool.hpp:106
void putFromISR(void *const b, std::uint_fast8_t const qsId) noexcept
QMPoolCtr m_nTot
Definition qmpool.hpp:107
void * getFromISR(std::uint_fast16_t const margin, std::uint_fast8_t const qsId) noexcept
QFreeBlock * m_start
Definition qmpool.hpp:103
void init(void *const poolSto, std::uint_fast32_t const poolSize, std::uint_fast16_t const blockSize) noexcept
Definition qf_mem.cpp:72
void * get(std::uint_fast16_t const margin, std::uint_fast8_t const qsId) noexcept
Definition qf_mem.cpp:132
QMPoolCtr getNMin() const noexcept
Definition qmpool.hpp:136
QP/C++ framework.
Definition qequeue.hpp:50
std::uint16_t QMPoolSize
Definition qmpool.hpp:58
std::uint16_t QMPoolCtr
Definition qmpool.hpp:68