QP/C 6.9.1
qmpool.h
Go to the documentation of this file.
1 
40 #ifndef QMPOOL_H
41 #define QMPOOL_H
42 
43 /****************************************************************************/
44 #ifndef QF_MPOOL_SIZ_SIZE
45 
48  #define QF_MPOOL_SIZ_SIZE 2U
49 #endif
50 #if (QF_MPOOL_SIZ_SIZE == 1U)
51 
61 #elif (QF_MPOOL_SIZ_SIZE == 2U)
62 
63  typedef uint16_t QMPoolSize;
64 #elif (QF_MPOOL_SIZ_SIZE == 4U)
65  typedef uint32_t QMPoolSize;
66 #else
67  #error "QF_MPOOL_SIZ_SIZE defined incorrectly, expected 1U, 2U, or 4U"
68 #endif
69 
70 /****************************************************************************/
71 #ifndef QF_MPOOL_CTR_SIZE
72 
75  #define QF_MPOOL_CTR_SIZE 2U
76 #endif
77 #if (QF_MPOOL_CTR_SIZE == 1U)
78 
87  typedef uint8_t QMPoolCtr;
88 #elif (QF_MPOOL_CTR_SIZE == 2U)
89  typedef uint16_t QMPoolCtr;
90 #elif (QF_MPOOL_CTR_SIZE == 4U)
91  typedef uint32_t QMPoolCtr;
92 #else
93  #error "QF_MPOOL_CTR_SIZE defined incorrectly, expected 1U, 2U, or 4U"
94 #endif
95 
96 /****************************************************************************/
118 typedef struct {
120  void * volatile free_head;
121 
123  void *start;
124 
126  void *end;
127 
130 
133 
135  QMPoolCtr volatile nFree;
136 
145 } QMPool;
146 
147 /* public functions: */
148 
150 void QMPool_init(QMPool * const me, void * const poolSto,
151  uint_fast32_t poolSize, uint_fast16_t blockSize);
152 
154 void *QMPool_get(QMPool * const me, uint_fast16_t const margin,
155  uint_fast8_t const qs_id);
156 
158 void QMPool_put(QMPool * const me, void *b,
159  uint_fast8_t const qs_id);
160 
167 #define QF_MPOOL_EL(evType_) \
168  struct { void *sto_[((sizeof(evType_) - 1U)/sizeof(void*)) + 1U]; }
169 
170 #endif /* QMPOOL_H */
171 
QMPool_get
void * QMPool_get(QMPool *const me, uint_fast16_t const margin, uint_fast8_t const qs_id)
Obtains a memory block from a memory pool.
Definition: qf_mem.c:213
QMPool::free_head
void *volatile free_head
The head of the linked list of free blocks.
Definition: qmpool.h:120
uint8_t
unsigned char uint8_t
exact-width 8-bit unsigned int
Definition: 16bit/stdint.h:29
QMPool::nTot
QMPoolCtr nTot
total number of blocks
Definition: qmpool.h:132
QMPoolCtr
uint8_t QMPoolCtr
The data type to store the block-counter based on the macro QF_MPOOL_CTR_SIZE.
Definition: qmpool.h:87
QMPool::end
void * end
the last memory block managed by this memory pool
Definition: qmpool.h:126
QMPool_init
void QMPool_init(QMPool *const me, void *const poolSto, uint_fast32_t poolSize, uint_fast16_t blockSize)
Initializes the native QF memory pool.
Definition: qf_mem.c:89
uint16_t
unsigned int uint16_t
exact-width 16-bit unsigned int
Definition: 16bit/stdint.h:30
QMPool::nMin
QMPoolCtr nMin
minimum number of free blocks ever present in this pool
Definition: qmpool.h:144
uint_fast8_t
unsigned int uint_fast8_t
fast at-least 8-bit unsigned int
Definition: 16bit/stdint.h:36
QMPool::nFree
QMPoolCtr volatile nFree
number of free blocks remaining
Definition: qmpool.h:135
QMPool::blockSize
QMPoolSize blockSize
maximum block size (in bytes)
Definition: qmpool.h:129
QMPoolSize
uint8_t QMPoolSize
The data type to store the block-size based on the macro QF_MPOOL_SIZ_SIZE.
Definition: qmpool.h:60
QMPool
Native QF Memory Pool.
Definition: qmpool.h:118
QMPool::start
void * start
the original start this pool
Definition: qmpool.h:123
uint_fast32_t
unsigned long uint_fast32_t
fast at-least 32-bit unsigned int
Definition: 16bit/stdint.h:40
QMPool_put
void QMPool_put(QMPool *const me, void *b, uint_fast8_t const qs_id)
Recycles a memory block back to a memory pool.
Definition: qf_mem.c:159
uint32_t
unsigned long int uint32_t
exact-width 32-bit unsigned int
Definition: 16bit/stdint.h:31
uint_fast16_t
unsigned int uint_fast16_t
fast at-least 16-bit unsigned int
Definition: 16bit/stdint.h:38