QP/C++  8.0.3
Real-Time Event Framework
Loading...
Searching...
No Matches
qmpool.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 QMPOOL_HPP_
30#define QMPOOL_HPP_
31
32#ifndef QF_MPOOL_SIZ_SIZE
33 #define QF_MPOOL_SIZ_SIZE 2U
34#endif
35#ifndef QF_MPOOL_CTR_SIZE
36 #define QF_MPOOL_CTR_SIZE 2U
37#endif
38
39#define QF_MPOOL_EL(evType_) struct { \
40 void * sto_[((sizeof(evType_) - 1U) / sizeof(void *)) + \
41 (sizeof(evType_) < (2U * sizeof(void *)) ? 2U : 1U)]; \
42}
43
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//============================================================================
68class QMPool {
69private:
70 void * * m_start;
71 void * * m_end;
72 void * * volatile m_freeHead;
77
78public:
80 : m_start(nullptr),
81 m_end(nullptr),
82 m_freeHead(nullptr),
83 m_blockSize(0U),
84 m_nTot(0U),
85 m_nFree(0U),
86 m_nMin(0U)
87 {}
88 void init(
89 void * const poolSto,
90 std::uint_fast32_t const poolSize,
91 std::uint_fast16_t const blockSize) noexcept;
92 void * get(
93 std::uint_fast16_t const margin,
94 std::uint_fast8_t const qsId) noexcept;
95 void put(
96 void * const block,
97 std::uint_fast8_t const qsId) noexcept;
98 QMPoolSize getBlockSize() const noexcept {
99 return m_blockSize;
100 }
101 QMPoolCtr getNMin() const noexcept {
102 #ifndef Q_UNSAFE
103 return m_nMin;
104 #else
105 return 0U;
106 #endif
107 }
108 QMPoolCtr getNFree() const noexcept {
109 return m_nFree;
110 }
111
112private:
113 QMPool(QEQueue const & other) = delete;
114 QMPool & operator=(QMPool const & other) = delete;
115
116public:
117
118#ifdef QF_ISR_API
120 std::uint_fast16_t const margin,
121 std::uint_fast8_t const qsId) noexcept;
122#endif // def QF_ISR_API
123
124#ifdef QF_ISR_API
126 void * const b,
127 std::uint_fast8_t const qsId) noexcept;
128#endif // def QF_ISR_API
129}; // class QMPool
130
131} // namespace QP
132
133#endif // QMPOOL_HPP_
Native QP event queue.
Definition qequeue.hpp:53
void * get(std::uint_fast16_t const margin, std::uint_fast8_t const qsId) noexcept
Definition qf_mem.cpp:103
QMPool & operator=(QMPool const &other)=delete
QMPool(QEQueue const &other)=delete
QMPoolCtr volatile m_nFree
Definition qmpool.hpp:75
QMPoolCtr getNFree() const noexcept
Definition qmpool.hpp:108
void init(void *const poolSto, std::uint_fast32_t const poolSize, std::uint_fast16_t const blockSize) noexcept
Definition qf_mem.cpp:48
QMPoolSize m_blockSize
Definition qmpool.hpp:73
QMPoolSize getBlockSize() const noexcept
Definition qmpool.hpp:98
void **volatile m_freeHead
Definition qmpool.hpp:72
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:174
void * getFromISR(std::uint_fast16_t const margin, std::uint_fast8_t const qsId) noexcept
QMPoolCtr m_nMin
Definition qmpool.hpp:76
void ** m_end
Definition qmpool.hpp:71
void ** m_start
Definition qmpool.hpp:70
QMPoolCtr m_nTot
Definition qmpool.hpp:74
QMPoolCtr getNMin() const noexcept
Definition qmpool.hpp:101
QP/C++ framework.
Definition qequeue.hpp:36
std::uint16_t QMPoolSize
Definition qmpool.hpp:50
std::uint16_t QMPoolCtr
Definition qmpool.hpp:60