QP/C++  7.4.0-rc.1
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 void init(
122 void * const poolSto,
123 std::uint_fast32_t const poolSize,
124 std::uint_fast16_t const blockSize) noexcept;
125 void * get(
126 std::uint_fast16_t const margin,
127 std::uint_fast8_t const qsId) noexcept;
128 void put(
129 void * const block,
130 std::uint_fast8_t const qsId) noexcept;
131 QMPoolSize getBlockSize() const noexcept;
132 QMPoolCtr getNMin() const noexcept {
133 return m_nMin;
134 }
135 QMPoolCtr getNFree() const noexcept {
136 return m_nFree;
137 }
138
139private:
140 QMPool(QEQueue const & other) = delete;
141 QMPool & operator=(QMPool const & other) = delete;
142
143public:
144
145#ifdef QF_ISR_API
147 std::uint_fast16_t const margin,
148 std::uint_fast8_t const qsId) noexcept;
149#endif // def QF_ISR_API
150
151#ifdef QF_ISR_API
153 void * const b,
154 std::uint_fast8_t const qsId) noexcept;
155#endif // def QF_ISR_API
156}; // class QMPool
157
158} // namespace QP
159//$enddecl${QF::QMPool} ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
160
161#endif // QMPOOL_HPP_
Native QP event queue.
Definition qequeue.hpp:70
Structure representing a free block in QP::QMPool.
Definition qmpool.hpp:84
QFreeBlock * m_next
Definition qmpool.hpp:86
std::uintptr_t m_next_dis
Definition qmpool.hpp:89
Native QF Memory Pool.
Definition qmpool.hpp:101
void * get(std::uint_fast16_t const margin, std::uint_fast8_t const qsId) noexcept
Definition qf_mem.cpp:139
QMPool & operator=(QMPool const &other)=delete
QMPool(QEQueue const &other)=delete
QMPoolCtr volatile m_nFree
Definition qmpool.hpp:108
QMPoolCtr getNFree() const noexcept
Definition qmpool.hpp:135
void init(void *const poolSto, std::uint_fast32_t const poolSize, std::uint_fast16_t const blockSize) noexcept
Definition qf_mem.cpp:72
QFreeBlock * m_start
Definition qmpool.hpp:103
QMPoolSize m_blockSize
Definition qmpool.hpp:106
QFreeBlock * m_end
Definition qmpool.hpp:104
QMPoolSize getBlockSize() const noexcept
Definition qf_mem.cpp:255
QFreeBlock *volatile m_free_head
Definition qmpool.hpp:105
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:216
void * getFromISR(std::uint_fast16_t const margin, std::uint_fast8_t const qsId) noexcept
QMPoolCtr m_nMin
Definition qmpool.hpp:109
QMPoolCtr m_nTot
Definition qmpool.hpp:107
QMPoolCtr getNMin() const noexcept
Definition qmpool.hpp:132
QP/C++ framework.
Definition qequeue.hpp:50
std::uint16_t QMPoolSize
Definition qmpool.hpp:58
std::uint16_t QMPoolCtr
Definition qmpool.hpp:68