QP/C  8.0.4
Real-Time Event Framework
Loading...
Searching...
No Matches
qmpool.h
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_H_
30#define QMPOOL_H_
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#if (QF_MPOOL_SIZ_SIZE == 1U)
45 typedef uint8_t QMPoolSize;
46#elif (QF_MPOOL_SIZ_SIZE == 2U)
47 typedef uint16_t QMPoolSize;
48#elif (QF_MPOOL_SIZ_SIZE == 4U)
49 typedef uint32_t QMPoolSize;
50#else
51 #error QF_MPOOL_SIZ_SIZE defined incorrectly, expected 1U, 2U, or 4U
52#endif
53
54#if (QF_MPOOL_CTR_SIZE == 1U)
55 typedef uint8_t QMPoolCtr;
56#elif (QF_MPOOL_CTR_SIZE == 2U)
57 typedef uint16_t QMPoolCtr;
58#elif (QF_MPOOL_CTR_SIZE == 4U)
59 typedef uint32_t QMPoolCtr;
60#else
61 #error QF_MPOOL_CTR_SIZE defined incorrectly, expected 1U, 2U, or 4U
62#endif
63
64//============================================================================
65//! @class QMPool
66typedef struct {
67 void * * start; //!< @private @memberof QMPool
68 void * * end; //!< @private @memberof QMPool
69 void * * volatile freeHead; //!< @private @memberof QMPool
70 QMPoolSize blockSize; //!< @private @memberof QMPool
71 QMPoolCtr nTot; //!< @private @memberof QMPool
72 QMPoolCtr volatile nFree; //!< @private @memberof QMPool
73 QMPoolCtr nMin; //!< @private @memberof QMPool
74} QMPool;
75
76//! @public @memberof QMPool
77void QMPool_init(QMPool * const me,
78 void * const poolSto,
79 uint_fast32_t const poolSize,
80 uint_fast16_t const blockSize);
81
82//! @public @memberof QMPool
83void * QMPool_get(QMPool * const me,
84 uint_fast16_t const margin,
85 uint_fast8_t const qsId);
86
87//! @public @memberof QMPool
88void QMPool_put(QMPool * const me,
89 void * const block,
90 uint_fast8_t const qsId);
91
92#endif // QMPOOL_H_
uint16_t QMPoolSize
The data type to store the block-size based on the macro QF_MPOOL_SIZ_SIZE.
Definition qmpool.h:47
uint16_t QMPoolCtr
The data type to store the block-counter based on the macro QF_MPOOL_CTR_SIZE.
Definition qmpool.h:57
Native QF Memory Pool.
Definition qmpool.h:66
void **volatile freeHead
Definition qmpool.h:69
void ** end
End of the memory managed by this memory pool.
Definition qmpool.h:68
void QMPool_put(QMPool *const me, void *const block, uint_fast8_t const qsId)
Recycles a memory block back to a memory pool.
Definition qf_mem.c:186
void * QMPool_get(QMPool *const me, uint_fast16_t const margin, uint_fast8_t const qsId)
Obtain a memory block from a memory pool.
Definition qf_mem.c:107
void ** start
Start of the memory managed by this memory pool.
Definition qmpool.h:67
QMPoolCtr volatile nFree
Number of free memory blocks remaining in the pool at this point.
Definition qmpool.h:72
void QMPool_init(QMPool *const me, void *const poolSto, uint_fast32_t const poolSize, uint_fast16_t const blockSize)
Initializes the native QF memory pool.
QMPoolSize blockSize
Memory block size [bytes] held by this fixed-size pool.
Definition qmpool.h:70
QMPoolCtr nMin
Minimum number of free blocks ever present in this pool.
Definition qmpool.h:73
QMPoolCtr nTot
Total number of memory blocks in this pool.
Definition qmpool.h:71