Reference Manual For QP/C++ 8.1.5
Toggle main menu visibility
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
namespace
QP
{
45
46
#if (QF_MPOOL_SIZ_SIZE == 1U)
47
using
QMPoolSize
= std::uint8_t;
48
#elif (QF_MPOOL_SIZ_SIZE == 2U)
49
using
QMPoolSize
= std::uint16_t;
50
#elif (QF_MPOOL_SIZ_SIZE == 4U)
51
using
QMPoolSize
= std::uint32_t;
52
#else
53
#error QF_MPOOL_SIZ_SIZE defined incorrectly, expected 1U, 2U, or 4U
54
#endif
55
56
#if (QF_MPOOL_CTR_SIZE == 1U)
57
using
QMPoolCtr
= std::uint8_t;
58
#elif (QF_MPOOL_CTR_SIZE == 2U)
59
using
QMPoolCtr
= std::uint16_t;
60
#elif (QF_MPOOL_CTR_SIZE == 4U)
61
using
QMPoolCtr
= std::uint32_t;
62
#else
63
#error QF_MPOOL_CTR_SIZE defined incorrectly, expected 1U, 2U, or 4U
64
#endif
65
66
//============================================================================
67
class
QMPool
{
68
private
:
69
void
* *
m_start
;
70
void
* *
m_end
;
71
void
* *m_freeHead;
72
QMPoolSize
m_blockSize
;
73
QMPoolCtr
m_nTot
;
74
QMPoolCtr
m_nFree
;
75
QMPoolCtr
m_nMin
;
76
77
public
:
78
QMPool
() noexcept;
79
void
init
(
80
void
* const poolSto,
81
std::uint_fast32_t const poolSize,
82
std::uint_fast16_t const blockSize) noexcept;
83
void
*
get
(
84
std::uint_fast16_t const margin,
85
std::uint_fast8_t const qsId) noexcept;
86
void
put
(
87
void
* const block,
88
std::uint_fast8_t const qsId) noexcept;
89
QMPoolSize
getBlockSize() const noexcept;
90
std::uint16_t getUse() const noexcept;
91
std::uint16_t getFree() const noexcept;
92
std::uint16_t getMin() const noexcept;
93
94
#ifdef QF_ISR_API
95
void
* getFromISR(
96
std::uint_fast16_t
const
margin,
97
std::uint_fast8_t
const
qsId)
noexcept
;
98
void
putFromISR(
99
void
*
const
b,
100
std::uint_fast8_t
const
qsId)
noexcept
;
101
#endif
// def QF_ISR_API
102
103
private
:
104
// friends...
105
friend
class
QS;
106
};
// class QMPool
107
108
}
// namespace QP
109
110
#endif
// QMPOOL_HPP_
QP::QMPool::get
void * get(std::uint_fast16_t const margin, std::uint_fast8_t const qsId) noexcept
Obtain a memory block from a memory pool.
Definition
qf_mem.cpp:121
QP::QMPool::init
void init(void *const poolSto, std::uint_fast32_t const poolSize, std::uint_fast16_t const blockSize) noexcept
Initializes the native QF memory pool.
Definition
qf_mem.cpp:58
QP::QMPool::m_blockSize
QMPoolSize m_blockSize
Memory block size [bytes] held by this fixed-size pool \clearpage .
Definition
qmpool.hpp:72
QP::QMPool::QMPool
QMPool() noexcept
Default constructor of QP::QMPool \clearpage .
Definition
qf_mem.cpp:48
QP::QMPool::m_nFree
QMPoolCtr m_nFree
Number of free memory blocks remaining in the pool at this point \clearpage .
Definition
qmpool.hpp:74
QP::QMPool::put
void put(void *const block, std::uint_fast8_t const qsId) noexcept
Recycles a memory block back to a memory pool.
Definition
qf_mem.cpp:200
QP::QMPool::m_nMin
QMPoolCtr m_nMin
Minimum number of free blocks ever present in this pool.
Definition
qmpool.hpp:75
QP::QMPool::m_end
void ** m_end
End of the memory managed by this memory pool \clearpage .
Definition
qmpool.hpp:70
QP::QMPool::m_start
void ** m_start
Start of the memory managed by this memory pool \clearpage .
Definition
qmpool.hpp:69
QP::QMPool::m_nTot
QMPoolCtr m_nTot
Total number of memory blocks in this pool \clearpage .
Definition
qmpool.hpp:73
QP
QP/C++ Framework namespace \clearpage .
Definition
qequeue.hpp:36
QP::QMPoolSize
std::uint16_t QMPoolSize
The data type to store the block-size based on the macro QF_MPOOL_SIZ_SIZE.
Definition
qmpool.hpp:49
QP::QMPoolCtr
std::uint16_t QMPoolCtr
The data type to store the block-counter based on the macro QF_MPOOL_CTR_SIZE.
Definition
qmpool.hpp:59
qpcpp
include
qmpool.hpp
©
Quantum Leaps
|
YouTube
|
GitHub
| created with
Spexygen
©
Quantum Leaps
|
YouTube
|
GitHub
| created with
Spexygen