QP/C  8.0.2
Real-Time Embedded Framework
Loading...
Searching...
No Matches
qmpool.h
Go to the documentation of this file.
1//============================================================================
2// QP/C Real-Time Embedded Framework (RTEF)
3// Version 8.0.2
4//
5// Copyright (C) 2005 Quantum Leaps, LLC. All rights reserved.
6//
7// Q u a n t u m L e a P s
8// ------------------------
9// Modern Embedded Software
10//
11// SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-QL-commercial
12//
13// This software is dual-licensed under the terms of the open-source GNU
14// General Public License (GPL) or under the terms of one of the closed-
15// source Quantum Leaps commercial licenses.
16//
17// Redistributions in source code must retain this top-level comment block.
18// Plagiarizing this software to sidestep the license obligations is illegal.
19//
20// NOTE:
21// The GPL does NOT permit the incorporation of this code into proprietary
22// programs. Please contact Quantum Leaps for commercial licensing options,
23// which expressly supersede the GPL and are designed explicitly for
24// closed-source distribution.
25//
26// Quantum Leaps contact information:
27// <www.state-machine.com/licensing>
28// <info@state-machine.com>
29//============================================================================
30#ifndef QMPOOL_H_
31#define QMPOOL_H_
32
33#ifndef QF_MPOOL_SIZ_SIZE
34 #define QF_MPOOL_SIZ_SIZE 2U
35#endif
36#ifndef QF_MPOOL_CTR_SIZE
37 #define QF_MPOOL_CTR_SIZE 2U
38#endif
39
40#define QF_MPOOL_EL(evType_) struct { \
41 void * sto_[((sizeof(evType_) - 1U) / sizeof(void *)) + \
42 (sizeof(evType_) < (2U * sizeof(void *)) ? 2U : 1U)]; \
43}
44
45#if (QF_MPOOL_SIZ_SIZE == 1U)
46 typedef uint8_t QMPoolSize;
47#elif (QF_MPOOL_SIZ_SIZE == 2U)
48 typedef uint16_t QMPoolSize;
49#elif (QF_MPOOL_SIZ_SIZE == 4U)
50 typedef uint32_t QMPoolSize;
51#else
52 #error QF_MPOOL_SIZ_SIZE defined incorrectly, expected 1U, 2U, or 4U
53#endif
54
55#if (QF_MPOOL_CTR_SIZE == 1U)
56 typedef uint8_t QMPoolCtr;
57#elif (QF_MPOOL_CTR_SIZE == 2U)
58 typedef uint16_t QMPoolCtr;
59#elif (QF_MPOOL_CTR_SIZE == 4U)
60 typedef uint32_t QMPoolCtr;
61#else
62 #error QF_MPOOL_CTR_SIZE defined incorrectly, expected 1U, 2U, or 4U
63#endif
64
65//============================================================================
66//! @class QMPool
67typedef struct {
68 void * * start; //!< @private @memberof QMPool
69 void * * end; //!< @private @memberof QMPool
70 void * * volatile freeHead; //!< @private @memberof QMPool
71 QMPoolSize blockSize; //!< @private @memberof QMPool
72 QMPoolCtr nTot; //!< @private @memberof QMPool
73 QMPoolCtr volatile nFree; //!< @private @memberof QMPool
74 QMPoolCtr nMin; //!< @private @memberof QMPool
75} QMPool;
76
77//! @public @memberof QMPool
78void QMPool_init(QMPool * const me,
79 void * const poolSto,
80 uint_fast32_t const poolSize,
81 uint_fast16_t const blockSize);
82
83//! @public @memberof QMPool
84void * QMPool_get(QMPool * const me,
85 uint_fast16_t const margin,
86 uint_fast8_t const qsId);
87
88//! @public @memberof QMPool
89void QMPool_put(QMPool * const me,
90 void * const block,
91 uint_fast8_t const qsId);
92
93#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:48
uint16_t QMPoolCtr
The data type to store the block-counter based on the macro QF_MPOOL_CTR_SIZE.
Definition qmpool.h:58
Native QF Memory Pool.
Definition qmpool.h:67
void **volatile freeHead
Definition qmpool.h:70
void ** end
End of the memory managed by this memory pool.
Definition qmpool.h:69
void QMPool_put(QMPool *const me, void *const block, uint_fast8_t const qsId)
Definition qf_mem.c:173
void * QMPool_get(QMPool *const me, uint_fast16_t const margin, uint_fast8_t const qsId)
Definition qf_mem.c:101
void ** start
Start of the memory managed by this memory pool.
Definition qmpool.h:68
QMPoolCtr volatile nFree
Number of free memory blocks remaining in the pool at this point.
Definition qmpool.h:73
void QMPool_init(QMPool *const me, void *const poolSto, uint_fast32_t const poolSize, uint_fast16_t const blockSize)
QMPoolSize blockSize
Memory block size [bytes] held by this fixed-size pool.
Definition qmpool.h:71
QMPoolCtr nMin
Minimum number of free blocks ever present in this pool.
Definition qmpool.h:74
QMPoolCtr nTot
Total number of memory blocks in this pool.
Definition qmpool.h:72