Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: TYBLE16_simple_data_logger TYBLE16_MP3_Air
memp_priv.h
00001 /** 00002 * @file 00003 * memory pools lwIP internal implementations (do not use in application code) 00004 */ 00005 00006 /* 00007 * Copyright (c) 2001-2004 Swedish Institute of Computer Science. 00008 * All rights reserved. 00009 * 00010 * Redistribution and use in source and binary forms, with or without modification, 00011 * are permitted provided that the following conditions are met: 00012 * 00013 * 1. Redistributions of source code must retain the above copyright notice, 00014 * this list of conditions and the following disclaimer. 00015 * 2. Redistributions in binary form must reproduce the above copyright notice, 00016 * this list of conditions and the following disclaimer in the documentation 00017 * and/or other materials provided with the distribution. 00018 * 3. The name of the author may not be used to endorse or promote products 00019 * derived from this software without specific prior written permission. 00020 * 00021 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 00022 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 00023 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT 00024 * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 00025 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 00026 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 00027 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 00028 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 00029 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 00030 * OF SUCH DAMAGE. 00031 * 00032 * This file is part of the lwIP TCP/IP stack. 00033 * 00034 * Author: Adam Dunkels <adam@sics.se> 00035 * 00036 */ 00037 00038 #ifndef LWIP_HDR_MEMP_PRIV_H 00039 #define LWIP_HDR_MEMP_PRIV_H 00040 00041 #include "lwip/opt.h" 00042 00043 #ifdef __cplusplus 00044 extern "C" { 00045 #endif 00046 00047 #include "lwip/mem.h" 00048 #include "lwip/priv/mem_priv.h" 00049 00050 #if MEMP_OVERFLOW_CHECK 00051 00052 00053 /* MEMP_SIZE: save space for struct memp and for sanity check */ 00054 #define MEMP_SIZE (LWIP_MEM_ALIGN_SIZE(sizeof(struct memp)) + MEM_SANITY_REGION_BEFORE_ALIGNED) 00055 #define MEMP_ALIGN_SIZE(x) (LWIP_MEM_ALIGN_SIZE(x) + MEM_SANITY_REGION_AFTER_ALIGNED) 00056 00057 #else /* MEMP_OVERFLOW_CHECK */ 00058 00059 /* No sanity checks 00060 * We don't need to preserve the struct memp while not allocated, so we 00061 * can save a little space and set MEMP_SIZE to 0. 00062 */ 00063 #define MEMP_SIZE 0 00064 #define MEMP_ALIGN_SIZE(x) (LWIP_MEM_ALIGN_SIZE(x)) 00065 00066 #endif /* MEMP_OVERFLOW_CHECK */ 00067 00068 #if !MEMP_MEM_MALLOC || MEMP_OVERFLOW_CHECK 00069 struct memp { 00070 struct memp *next; 00071 #if MEMP_OVERFLOW_CHECK 00072 const char *file; 00073 int line; 00074 #endif /* MEMP_OVERFLOW_CHECK */ 00075 }; 00076 #endif /* !MEMP_MEM_MALLOC || MEMP_OVERFLOW_CHECK */ 00077 00078 #if MEM_USE_POOLS && MEMP_USE_CUSTOM_POOLS 00079 /* Use a helper type to get the start and end of the user "memory pools" for mem_malloc */ 00080 typedef enum { 00081 /* Get the first (via: 00082 MEMP_POOL_HELPER_START = ((u8_t) 1*MEMP_POOL_A + 0*MEMP_POOL_B + 0*MEMP_POOL_C + 0)*/ 00083 MEMP_POOL_HELPER_FIRST = ((u8_t) 00084 #define LWIP_MEMPOOL(name,num,size,desc) 00085 #define LWIP_MALLOC_MEMPOOL_START 1 00086 #define LWIP_MALLOC_MEMPOOL(num, size) * MEMP_POOL_##size + 0 00087 #define LWIP_MALLOC_MEMPOOL_END 00088 #include "lwip/priv/memp_std.h" 00089 ) , 00090 /* Get the last (via: 00091 MEMP_POOL_HELPER_END = ((u8_t) 0 + MEMP_POOL_A*0 + MEMP_POOL_B*0 + MEMP_POOL_C*1) */ 00092 MEMP_POOL_HELPER_LAST = ((u8_t) 00093 #define LWIP_MEMPOOL(name,num,size,desc) 00094 #define LWIP_MALLOC_MEMPOOL_START 00095 #define LWIP_MALLOC_MEMPOOL(num, size) 0 + MEMP_POOL_##size * 00096 #define LWIP_MALLOC_MEMPOOL_END 1 00097 #include "lwip/priv/memp_std.h" 00098 ) 00099 } memp_pool_helper_t; 00100 00101 /* The actual start and stop values are here (cast them over) 00102 We use this helper type and these defines so we can avoid using const memp_t values */ 00103 #define MEMP_POOL_FIRST ((memp_t) MEMP_POOL_HELPER_FIRST) 00104 #define MEMP_POOL_LAST ((memp_t) MEMP_POOL_HELPER_LAST) 00105 #endif /* MEM_USE_POOLS && MEMP_USE_CUSTOM_POOLS */ 00106 00107 /** Memory pool descriptor */ 00108 struct memp_desc { 00109 #if defined(LWIP_DEBUG) || MEMP_OVERFLOW_CHECK || LWIP_STATS_DISPLAY 00110 /** Textual description */ 00111 const char *desc; 00112 #endif /* LWIP_DEBUG || MEMP_OVERFLOW_CHECK || LWIP_STATS_DISPLAY */ 00113 #if MEMP_STATS 00114 /** Statistics */ 00115 struct stats_mem *stats; 00116 #endif 00117 00118 /** Element size */ 00119 u16_t size; 00120 00121 #if !MEMP_MEM_MALLOC 00122 /** Number of elements */ 00123 u16_t num; 00124 00125 /** Base address */ 00126 u8_t *base; 00127 00128 /** First free element of each pool. Elements form a linked list. */ 00129 struct memp **tab; 00130 #endif /* MEMP_MEM_MALLOC */ 00131 }; 00132 00133 #if defined(LWIP_DEBUG) || MEMP_OVERFLOW_CHECK || LWIP_STATS_DISPLAY 00134 #define DECLARE_LWIP_MEMPOOL_DESC(desc) (desc), 00135 #else 00136 #define DECLARE_LWIP_MEMPOOL_DESC(desc) 00137 #endif 00138 00139 #if MEMP_STATS 00140 #define LWIP_MEMPOOL_DECLARE_STATS_INSTANCE(name) static struct stats_mem name; 00141 #define LWIP_MEMPOOL_DECLARE_STATS_REFERENCE(name) &name, 00142 #else 00143 #define LWIP_MEMPOOL_DECLARE_STATS_INSTANCE(name) 00144 #define LWIP_MEMPOOL_DECLARE_STATS_REFERENCE(name) 00145 #endif 00146 00147 void memp_init_pool(const struct memp_desc *desc); 00148 00149 #if MEMP_OVERFLOW_CHECK 00150 void *memp_malloc_pool_fn(const struct memp_desc* desc, const char* file, const int line); 00151 #define memp_malloc_pool(d) memp_malloc_pool_fn((d), __FILE__, __LINE__) 00152 #else 00153 void *memp_malloc_pool(const struct memp_desc *desc); 00154 #endif 00155 void memp_free_pool(const struct memp_desc* desc, void *mem); 00156 00157 #ifdef __cplusplus 00158 } 00159 #endif 00160 00161 #endif /* LWIP_HDR_MEMP_PRIV_H */
Generated on Tue Jul 12 2022 13:54:35 by
