RKH
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 site: http://vortexmakes.com/que-es/
28  * RKH GitHub: https://github.com/vortexmakes/RKH
29  * RKH Sourceforge: https://sourceforge.net/projects/rkh-reactivesys/
30  * e-mail: lf@vortexmakes.com
31  * ---------------------------------------------------------------------------
32  */
33 
47 /* -------------------------- Development history -------------------------- */
48 /*
49  * 2015.10.24 LeFr v2.4.05 Initial version
50  */
51 
52 /* -------------------------------- Authors -------------------------------- */
53 /*
54  * LeFr Leandro Francucci lf@vortexmakes.com
55  */
56 
57 /* --------------------------------- Notes --------------------------------- */
58 /* --------------------------------- Module -------------------------------- */
59 #ifndef __RKHMEMPOOL_H__
60 #define __RKHMEMPOOL_H__
61 
62 /* ----------------------------- Include files ----------------------------- */
63 #include "rkhtype.h"
64 #include "rkhcfg.h"
65 
66 /* ---------------------- External C language linkage ---------------------- */
67 #ifdef __cplusplus
68 extern "C" {
69 #endif
70 
71 /* --------------------------------- Macros -------------------------------- */
72 /* -------------------------------- Constants ------------------------------ */
73 /* ------------------------------- Data types ------------------------------ */
79 #if RKH_CFG_MP_SIZEOF_NBLOCK == 8
80 typedef rui8_t RKH_MPNB_T;
81 #elif RKH_CFG_MP_SIZEOF_NBLOCK == 16
82 typedef rui16_t RKH_MPNB_T;
83 #elif RKH_CFG_MP_SIZEOF_NBLOCK == 32
84 typedef rui32_t RKH_MPNB_T;
85 #else
86 typedef rui8_t RKH_MPNB_T;
87 #endif
88 
94 #if RKH_CFG_MP_SIZEOF_BSIZE == 8
95 typedef rui8_t RKH_MPBS_T;
96 #elif RKH_CFG_MP_SIZEOF_BSIZE == 16
97 typedef rui16_t RKH_MPBS_T;
98 #elif RKH_CFG_MP_SIZEOF_BSIZE == 32
99 typedef rui32_t RKH_MPBS_T;
100 #else
101 typedef rui8_t RKH_MPBS_T;
102 #endif
103 
109 typedef struct
110 {
115  rui8_t inits;
116 
121  rui8_t gets;
122 
127  rui8_t puts;
128 
133  rui8_t free;
134 
139  rui8_t full;
140 } RKH_MPI_T;
141 
191 typedef struct RKH_MEMPOOL_T
192 {
200  void *free;
201 
207 
219 
231 
232 #if RKH_CFG_MP_REDUCED_EN == RKH_DISABLED
240  void *start;
241 
246  void *end;
247 
256 #if RKH_CFG_MP_GET_LWM_EN == RKH_ENABLED
258 #endif
259 
260 #endif
261 
266 #if RKH_CFG_MP_GET_INFO_EN == RKH_ENABLED
268 #endif
269 } RKH_MEMPOOL_T;
270 
271 /* -------------------------- External variables --------------------------- */
272 /* -------------------------- Function prototypes -------------------------- */
308 void rkh_memPool_init(RKH_MEMPOOL_T *mp, void *sstart, rui16_t ssize,
309  RKH_MPBS_T bsize);
310 
323 
335 void rkh_memPool_put(RKH_MEMPOOL_T *mp, void *blk);
336 
353 
370 
389 
410 
424 
425 /* -------------------- External C language linkage end -------------------- */
426 #ifdef __cplusplus
427 }
428 #endif
429 
430 /* ------------------------------ Module end ------------------------------- */
431 #endif
432 
433 /* ------------------------------ End of file ------------------------------ */
void rkh_memPool_get_info(RKH_MEMPOOL_T *mp, RKH_MPI_T *mpi)
Retrieves performance information for a particular 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...
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.
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.
void rkh_memPool_clear_info(RKH_MEMPOOL_T *mp)
Clear 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.
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...
RKH user configurations.
rui8_t RKH_MPBS_T
Definition: rkhmempool.h:95
rui8_t RKH_MPNB_T
Definition: rkhmempool.h:80
Defines the data types that uses RKH.
Defines the data structure used to memory block pool facility.
Definition: rkhmempool.h:192
RKH_MPNB_T nblocks
Total number of blocks in bytes.
Definition: rkhmempool.h:218
RKH_MPBS_T bsize
Maximum block size in bytes.
Definition: rkhmempool.h:230
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:257
void * start
The start of the original pool buffer.
Definition: rkhmempool.h:240
void * end
The last block in this pool.
Definition: rkhmempool.h:246
void * free
The head of the linked list of free blocks.
Definition: rkhmempool.h:200
RKH_MPI_T mpi
Definition: rkhmempool.h:267
RKH_MPNB_T nfree
Number of free blocks remaining.
Definition: rkhmempool.h:206
Defines the data structure into which the performance information for memory pools is stored.
Definition: rkhmempool.h:110
rui8_t puts
Number of put memory block requests.
Definition: rkhmempool.h:127
rui8_t full
Number of full retrieves.
Definition: rkhmempool.h:139
rui8_t free
Number of no free retrieves.
Definition: rkhmempool.h:133
rui8_t gets
Number of get memory block requests.
Definition: rkhmempool.h:121
rui8_t inits
Number of pool create requests.
Definition: rkhmempool.h:115