ChibiOS/RT Architecture - Reference Manual - Guides |
00001 /* 00002 ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010 Giovanni Di Sirio. 00003 00004 This file is part of ChibiOS/RT. 00005 00006 ChibiOS/RT is free software; you can redistribute it and/or modify 00007 it under the terms of the GNU General Public License as published by 00008 the Free Software Foundation; either version 3 of the License, or 00009 (at your option) any later version. 00010 00011 ChibiOS/RT is distributed in the hope that it will be useful, 00012 but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 GNU General Public License for more details. 00015 00016 You should have received a copy of the GNU General Public License 00017 along with this program. If not, see <http://www.gnu.org/licenses/>. 00018 00019 --- 00020 00021 A special exception to the GPL can be applied should you wish to distribute 00022 a combined work that includes ChibiOS/RT, without being obliged to provide 00023 the source code for any proprietary components. See the file exception.txt 00024 for full details of how and when the exception can be applied. 00025 */ 00026 00027 /** 00028 * @file chmempools.h 00029 * @brief Memory Pools macros and structures. 00030 * 00031 * @addtogroup pools 00032 * @{ 00033 */ 00034 00035 #ifndef _CHMEMPOOLS_H_ 00036 #define _CHMEMPOOLS_H_ 00037 00038 #if CH_USE_MEMPOOLS 00039 00040 /** 00041 * @brief Memory pool free object header. 00042 */ 00043 struct pool_header { 00044 struct pool_header *ph_next; /**< @brief Pointer to the next pool 00045 header in the list. */ 00046 }; 00047 00048 /** 00049 * @brief Memory pool descriptor. 00050 */ 00051 typedef struct { 00052 struct pool_header *mp_next; /**< @brief Pointer to the header. */ 00053 size_t mp_object_size; /**< @brief Memory pool objects 00054 size. */ 00055 memgetfunc_t mp_provider; /**< @brief Memory blocks provider for 00056 this pool. */ 00057 } MemoryPool; 00058 00059 /** 00060 * @brief Data part of a static memory pool initializer. 00061 * @details This macro should be used when statically initializing a 00062 * memory pool that is part of a bigger structure. 00063 * 00064 * @param[in] name the name of the memory pool variable 00065 * @param[in] size size of the memory pool contained objects 00066 * @param[in] provider memory provider function for the memory pool 00067 */ 00068 #define _MEMORYPOOL_DATA(name, size, provider) \ 00069 {NULL, MEM_ALIGN_SIZE(size), provider} 00070 00071 /** 00072 * @brief Static memory pool initializer in hungry mode. 00073 * @details Statically initialized memory pools require no explicit 00074 * initialization using @p chPoolInit(). 00075 * 00076 * @param[in] name the name of the memory pool variable 00077 * @param[in] size size of the memory pool contained objects 00078 * @param[in] provider memory provider function for the memory pool or @p NULL 00079 * if the pool is not allowed to grow automatically 00080 */ 00081 #define MEMORYPOOL_DECL(name, size, provider) \ 00082 MemoryPool name = _MEMORYPOOL_DATA(name, size, provider) 00083 00084 #ifdef __cplusplus 00085 extern "C" { 00086 #endif 00087 void chPoolInit(MemoryPool *mp, size_t size, memgetfunc_t provider); 00088 void *chPoolAllocI(MemoryPool *mp); 00089 void *chPoolAlloc(MemoryPool *mp); 00090 void chPoolFreeI(MemoryPool *mp, void *objp); 00091 void chPoolFree(MemoryPool *mp, void *objp); 00092 #ifdef __cplusplus 00093 } 00094 #endif 00095 00096 #endif /* CH_USE_MEMPOOLS */ 00097 00098 #endif /* _CHMEMPOOLS_H_ */ 00099 00100 /** @} */