QP/C++  7.0.1
Real-Time Embedded Framework
qmpool.hpp
Go to the documentation of this file.
1//============================================================================
2// QP/C++ Real-Time Embedded Framework (RTEF)
3// Copyright (C) 2005 Quantum Leaps, LLC. All rights reserved.
4//
5// SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-QL-commercial
6//
7// This software is dual-licensed under the terms of the open source GNU
8// General Public License version 3 (or any later version), or alternatively,
9// under the terms of one of the closed source Quantum Leaps commercial
10// licenses.
11//
12// The terms of the open source GNU General Public License version 3
13// can be found at: <www.gnu.org/licenses/gpl-3.0>
14//
15// The terms of the closed source Quantum Leaps commercial licenses
16// can be found at: <www.state-machine.com/licensing>
17//
18// Redistributions in source code must retain this top-level comment block.
19// Plagiarizing this software to sidestep the license obligations is illegal.
20//
21// Contact information:
22// <www.state-machine.com>
23// <info@state-machine.com>
24//============================================================================
30
31#ifndef QMPOOL_HPP
32#define QMPOOL_HPP
33
34#ifndef QF_MPOOL_SIZ_SIZE
37 #define QF_MPOOL_SIZ_SIZE 2U
38#endif
39
40#ifndef QF_MPOOL_CTR_SIZE
43 #define QF_MPOOL_CTR_SIZE 2
44#endif
45
46namespace QP {
47#if (QF_MPOOL_SIZ_SIZE == 1U)
48 using QMPoolSize = std::uint8_t;
49#elif (QF_MPOOL_SIZ_SIZE == 2U)
56 using QMPoolSize = std::uint16_t;
57#elif (QF_MPOOL_SIZ_SIZE == 4U)
58 using QMPoolSize = std::uint32_t;
59#else
60 #error "QF_MPOOL_SIZ_SIZE defined incorrectly, expected 1U, 2U, or 4U"
61#endif
62
63#if (QF_MPOOL_CTR_SIZE == 1U)
64 using QMPoolCtr = std::uint8_t;
65#elif (QF_MPOOL_CTR_SIZE == 2U)
72 using QMPoolCtr = std::uint16_t;
73#elif (QF_MPOOL_CTR_SIZE == 4U)
74 using QMPoolCtr = std::uint32_t;
75#else
76 #error "QF_MPOOL_CTR_SIZE defined incorrectly, expected 1U, 2U, or 4U"
77#endif
78
79//============================================================================
101class QMPool {
102private:
103
105 void *m_start;
106
108 void *m_end;
109
111 void * volatile m_free_head;
112
115
118
121
130
131public:
132 QMPool(void);
133
165 void init(void * const poolSto, std::uint_fast32_t poolSize,
166 std::uint_fast16_t blockSize) noexcept;
167
199 void *get(std::uint_fast16_t const margin,
200 std::uint_fast8_t const qs_id) noexcept;
201
220 void put(void * const b, std::uint_fast8_t const qs_id) noexcept;
221
223 QMPoolSize getBlockSize(void) const noexcept {
224 return m_blockSize;
225 }
226
227// duplicated API to be used exclusively inside ISRs (useful in some QP ports)
228#ifdef QF_ISR_API
229 void *getFromISR(std::uint_fast16_t const margin,
230 std::uint_fast8_t const qs_id) noexcept;
231 void putFromISR(void * const b,
232 std::uint_fast8_t const qs_id) noexcept;
233#endif // QF_ISR_API
234
235private:
237 QMPool(QMPool const &) = delete;
238
240 QMPool &operator=(QMPool const &) = delete;
241
242 friend class QF;
243 friend class QS;
244};
245
246} // namespace QP
247
249#define QF_MPOOL_EL(type_) \
250 struct { void *sto_[((sizeof(type_) - 1U)/sizeof(void*)) + 1U]; }
251
252#endif // QMPOOL_HPP
QF real-time active object framework.
Definition: qf.hpp:790
Native QF memory pool class.
Definition: qmpool.hpp:101
QMPool & operator=(QMPool const &)=delete
void put(void *const b, std::uint_fast8_t const qs_id) noexcept
Returns a memory block back to a memory pool.
Definition: qf_mem.cpp:194
void * m_end
end of the memory managed by this memory pool
Definition: qmpool.hpp:108
void init(void *const poolSto, std::uint_fast32_t poolSize, std::uint_fast16_t blockSize) noexcept
Initializes the native QF event pool.
Definition: qf_mem.cpp:72
QMPoolSize m_blockSize
maximum block size (in bytes)
Definition: qmpool.hpp:114
void *volatile m_free_head
head of linked list of free blocks
Definition: qmpool.hpp:111
void * m_start
start of the memory managed by this memory pool
Definition: qmpool.hpp:105
void * get(std::uint_fast16_t const margin, std::uint_fast8_t const qs_id) noexcept
Obtains a memory block from a memory pool.
Definition: qf_mem.cpp:127
QMPoolCtr m_nMin
minimum number of free blocks ever present in this pool
Definition: qmpool.hpp:129
QMPoolCtr volatile m_nFree
number of free blocks remaining
Definition: qmpool.hpp:120
QMPool(void)
public default constructor
Definition: qf_mem.cpp:61
QMPoolCtr m_nTot
total number of blocks
Definition: qmpool.hpp:117
QMPoolSize getBlockSize(void) const noexcept
return the fixed block-size of the blocks managed by this pool
Definition: qmpool.hpp:223
QMPool(QMPool const &)=delete
disallow copying of QMPools
QS software tracing facilities for output (QS-TX)
Definition: qs.hpp:74
namespace associated with the QP/C++ framework
Definition: exa_native.dox:1
std::uint16_t QMPoolSize
The data type to store the block-size based on the macro #QF_MPOOL_SIZ_SIZE.
Definition: qmpool.hpp:56
std::uint16_t QMPoolCtr
The data type to store the block-counter based on the macro #QF_MPOOL_CTR_SIZE.
Definition: qmpool.hpp:72