RKH
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
rkhmempool.h
Go to the documentation of this file.
1 /*
2  * --------------------------------------------------------------------------
3  *
4  * Framework RKH
5  * -------------
6  *
7  * State-machine framework for reactive embedded systems
8  *
9  * Copyright (C) 2010 Leandro Francucci.
10  * All rights reserved. Protected by international copyright laws.
11  *
12  *
13  * RKH is free software: you can redistribute it and/or modify it under the
14  * terms of the GNU General Public License as published by the Free Software
15  * Foundation, either version 3 of the License, or (at your option) any
16  * later version.
17  *
18  * RKH is distributed in the hope that it will be useful, but WITHOUT ANY
19  * WARRANTY; without even the implied warranty of MERCHANTABILITY or
20  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
21  * more details.
22  *
23  * You should have received a copy of the GNU General Public License along
24  * with RKH, see copying.txt file.
25  *
26  * Contact information:
27  * RKH web site: http://sourceforge.net/projects/rkh-reactivesys/
28  * e-mail: francuccilea@gmail.com
29  * ---------------------------------------------------------------------------
30  */
31 
45 /* -------------------------- Development history -------------------------- */
46 /*
47  * 2015.10.24 LeFr v2.4.05 Initial version
48  */
49 
50 /* -------------------------------- Authors -------------------------------- */
51 /*
52  * LeFr Leandro Francucci francuccilea@gmail.com
53  */
54 
55 /* --------------------------------- Notes --------------------------------- */
56 /* --------------------------------- Module -------------------------------- */
57 #ifndef __RKHMEMPOOL_H__
58 #define __RKHMEMPOOL_H__
59 
60 /* ----------------------------- Include files ----------------------------- */
61 #include "rkhtype.h"
62 #include "rkhcfg.h"
63 
64 /* ---------------------- External C language linkage ---------------------- */
65 #ifdef __cplusplus
66 extern "C" {
67 #endif
68 
69 /* --------------------------------- Macros -------------------------------- */
70 /* -------------------------------- Constants ------------------------------ */
71 /* ------------------------------- Data types ------------------------------ */
77 #if RKH_CFG_MP_SIZEOF_NBLOCK == 8
78 typedef rui8_t RKH_MPNB_T;
79 #elif RKH_CFG_MP_SIZEOF_NBLOCK == 16
80 typedef rui16_t RKH_MPNB_T;
81 #elif RKH_CFG_MP_SIZEOF_NBLOCK == 32
82 typedef rui32_t RKH_MPNB_T;
83 #else
84 typedef rui8_t RKH_MPNB_T;
85 #endif
86 
92 #if RKH_CFG_MP_SIZEOF_BSIZE == 8
93 typedef rui8_t RKH_MPBS_T;
94 #elif RKH_CFG_MP_SIZEOF_BSIZE == 16
95 typedef rui16_t RKH_MPBS_T;
96 #elif RKH_CFG_MP_SIZEOF_BSIZE == 32
97 typedef rui32_t RKH_MPBS_T;
98 #else
99 typedef rui8_t RKH_MPBS_T;
100 #endif
101 
107 typedef struct
108 {
113  rui8_t inits;
114 
119  rui8_t gets;
120 
125  rui8_t puts;
126 
131  rui8_t free;
132 
137  rui8_t full;
138 } RKH_MPI_T;
139 
189 typedef struct RKH_MEMPOOL_T
190 {
198  void *free;
199 
204  RKH_MPNB_T nfree;
205 
216  RKH_MPNB_T nblocks;
217 
228  RKH_MPBS_T bsize;
229 
230 #if RKH_CFG_MP_REDUCED_EN == RKH_DISABLED
231 
238  void *start;
239 
244  void *end;
245 
254 #if RKH_CFG_MP_GET_LWM_EN == RKH_ENABLED
255  RKH_MPNB_T nmin;
256 #endif
257 
258 #endif
259 
264 #if RKH_CFG_MP_GET_INFO_EN == RKH_ENABLED
266 #endif
267 } RKH_MEMPOOL_T;
268 
269 /* -------------------------- External variables --------------------------- */
270 /* -------------------------- Function prototypes -------------------------- */
306 void rkh_memPool_init(RKH_MEMPOOL_T *mp, void *sstart, rui16_t ssize,
307  RKH_MPBS_T bsize);
308 
320 void *rkh_memPool_get(RKH_MEMPOOL_T *mp);
321 
333 void rkh_memPool_put(RKH_MEMPOOL_T *mp, void *blk);
334 
350 RKH_MPBS_T rkh_memPool_get_bsize(RKH_MEMPOOL_T *mp);
351 
367 RKH_MPNB_T rkh_memPool_get_nfree(RKH_MEMPOOL_T *mp);
368 
387 
408 
422 
423 /* -------------------- External C language linkage end -------------------- */
424 #ifdef __cplusplus
425 }
426 #endif
427 
428 /* ------------------------------ Module end ------------------------------- */
429 #endif
430 
431 /* ------------------------------ End of file ------------------------------ */
Defines the data structure used to memory block pool facility.
Definition: rkhmempool.h:189
rui8_t inits
Number of pool create requests.
Definition: rkhmempool.h:113
rui8_t gets
Number of get memory block requests.
Definition: rkhmempool.h:119
void rkh_memPool_init(RKH_MEMPOOL_T *mp, void *sstart, rui16_t ssize, RKH_MPBS_T bsize)
Initializes the previously allocated memory pool data strcuture RKH_MEMPOOL_T.
Defines the data structure into which the performance information for memory pools is stored...
Definition: rkhmempool.h:107
rui8_t full
Number of full retrieves.
Definition: rkhmempool.h:137
RKH_MPBS_T bsize
Maximum block size in bytes.
Definition: rkhmempool.h:228
void * start
The start of the original pool buffer.
Definition: rkhmempool.h:238
RKH_MPNB_T nfree
Number of free blocks remaining.
Definition: rkhmempool.h:204
RKH user configurations.
rui8_t RKH_MPBS_T
Definition: rkhmempool.h:93
void * end
The last block in this pool.
Definition: rkhmempool.h:244
void rkh_memPool_get_info(RKH_MEMPOOL_T *mp, RKH_MPI_T *mpi)
Retrieves performance information for a particular memory pool.
void * rkh_memPool_get(RKH_MEMPOOL_T *mp)
Get a memory block from one of the previously allocated memory pool.
void rkh_memPool_put(RKH_MEMPOOL_T *mp, void *blk)
When the application is done with the memory block, it must be returned to the appropiate memory pool...
rui8_t RKH_MPNB_T
Definition: rkhmempool.h:78
RKH_MPBS_T rkh_memPool_get_bsize(RKH_MEMPOOL_T *mp)
Retrieves the size of memory block in bytes.
RKH_MPNB_T rkh_memPool_get_nfree(RKH_MEMPOOL_T *mp)
Retrieves the current number of free memory blocks in the pool.
rui8_t puts
Number of put memory block requests.
Definition: rkhmempool.h:125
RKH_MPNB_T nmin
Minimum number of free blocks ever in this pool, i.e. holds the lowest number of free blocks ever pre...
Definition: rkhmempool.h:255
rui8_t free
Number of no free retrieves.
Definition: rkhmempool.h:131
RKH_MPNB_T nblocks
Total number of blocks in bytes.
Definition: rkhmempool.h:216
RKH_MPNB_T rkh_memPool_get_low_wmark(RKH_MEMPOOL_T *mp)
Retrieves the lowest number of free blocks ever present in the pool. This number provides valuable em...
void rkh_memPool_clear_info(RKH_MEMPOOL_T *mp)
Clear performance information for a particular memory pool.
Defines the data types that uses RKH.
void * free
The head of the linked list of free blocks.
Definition: rkhmempool.h:198
RKH_MPI_T mpi
Definition: rkhmempool.h:265