#include "lwip/opt.h"
#include "lwip/memp.h"
#include "lwip/pbuf.h"
#include "lwip/udp.h"
#include "lwip/tcp.h"
#include "lwip/api.h"
#include "lwip/api_msg.h"
#include "lwip/tcpip.h"
#include "lwip/sys.h"
#include "lwip/stats.h"
Include dependency graph for memp.c:
Go to the source code of this file.
Data Structures | |
struct | memp |
Functions | |
void | memp_init (void) |
void * | memp_malloc (memp_t type) |
void * | memp_mallocp (memp_t type) |
void | memp_free (memp_t type, void *mem) |
void | memp_freep (memp_t type, void *mem) |
Variables | |
memp * | memp_tab [MEMP_MAX] |
const u16_t | memp_sizes [MEMP_MAX] |
const u16_t | memp_num [MEMP_MAX] |
u8_t | memp_memory [(MEMP_NUM_PBUF *MEM_ALIGN_SIZE(sizeof(struct pbuf)+sizeof(struct memp))+MEMP_NUM_UDP_PCB *MEM_ALIGN_SIZE(sizeof(struct udp_pcb)+sizeof(struct memp))+MEMP_NUM_TCP_PCB *MEM_ALIGN_SIZE(sizeof(struct tcp_pcb)+sizeof(struct memp))+MEMP_NUM_TCP_PCB_LISTEN *MEM_ALIGN_SIZE(sizeof(struct tcp_pcb_listen)+sizeof(struct memp))+MEMP_NUM_TCP_SEG *MEM_ALIGN_SIZE(sizeof(struct tcp_seg)+sizeof(struct memp))+MEMP_NUM_NETBUF *MEM_ALIGN_SIZE(sizeof(struct netbuf)+sizeof(struct memp))+MEMP_NUM_NETCONN *MEM_ALIGN_SIZE(sizeof(struct netconn)+sizeof(struct memp))+MEMP_NUM_API_MSG *MEM_ALIGN_SIZE(sizeof(struct api_msg)+sizeof(struct memp))+MEMP_NUM_TCPIP_MSG *MEM_ALIGN_SIZE(sizeof(struct tcpip_msg)+sizeof(struct memp)))] |
sys_sem_t | mutex |
|
Definition at line 238 of file memp.c. References LWIP_ASSERT, memp_tab, NULL, and u8_t. Referenced by memp_freep(), netconn_delete(), and tcpip_apimsg().
00239 { 00240 struct memp *memp; 00241 00242 if(mem == NULL) { 00243 return; 00244 } 00245 memp = (struct memp *)((u8_t *)mem - sizeof(struct memp)); 00246 00247 #ifdef MEMP_STATS 00248 lwip_stats.memp[type].used--; 00249 #endif /* MEMP_STATS */ 00250 00251 memp->next = memp_tab[type]; 00252 memp_tab[type] = memp; 00253 00254 LWIP_ASSERT("memp sanity", memp_sanity()); 00255 00256 return; 00257 } |
|
Definition at line 260 of file memp.c. References memp_free(), mutex, sys_sem_signal(), and sys_sem_wait(). Referenced by netbuf_chain(), netbuf_delete(), netconn_bind(), netconn_close(), netconn_connect(), netconn_delete(), netconn_disconnect(), netconn_listen(), netconn_new(), netconn_recv(), netconn_send(), netconn_write(), pbuf_free(), and tcpip_thread().
00261 { 00262 #if SYS_LIGHTWEIGHT_PROT 00263 SYS_ARCH_DECL_PROTECT(old_level); 00264 SYS_ARCH_PROTECT(old_level); 00265 #else /* SYS_LIGHTWEIGHT_PROT */ 00266 sys_sem_wait(mutex); 00267 #endif /* SYS_LIGHTWEIGHT_PROT */ 00268 00269 memp_free(type, mem); 00270 00271 #if SYS_LIGHTWEIGHT_PROT 00272 SYS_ARCH_UNPROTECT(old_level); 00273 #else /* SYS_LIGHTWEIGHT_PROT */ 00274 sys_sem_signal(mutex); 00275 #endif /* SYS_LIGHTWEIGHT_PROT */ 00276 00277 } |
Here is the call graph for this function:
|
Definition at line 141 of file memp.c. References MEM_ALIGN, MEM_ALIGN_SIZE, MEMP_MAX, memp_memory, memp_num, memp_sizes, memp_tab, mutex, memp::next, NULL, sys_sem_new(), u16_t, and u8_t.
00142 { 00143 struct memp *m, *memp; 00144 u16_t i, j; 00145 u16_t size; 00146 00147 #ifdef MEMP_STATS 00148 for(i = 0; i < MEMP_MAX; ++i) { 00149 lwip_stats.memp[i].used = lwip_stats.memp[i].max = 00150 lwip_stats.memp[i].err = 0; 00151 lwip_stats.memp[i].avail = memp_num[i]; 00152 } 00153 #endif /* MEMP_STATS */ 00154 00155 memp = (struct memp *)&memp_memory[0]; 00156 for(i = 0; i < MEMP_MAX; ++i) { 00157 size = MEM_ALIGN_SIZE(memp_sizes[i] + sizeof(struct memp)); 00158 if(memp_num[i] > 0) { 00159 memp_tab[i] = memp; 00160 m = memp; 00161 00162 for(j = 0; j < memp_num[i]; ++j) { 00163 m->next = (struct memp *)MEM_ALIGN((u8_t *)m + size); 00164 memp = m; 00165 m = m->next; 00166 } 00167 memp->next = NULL; 00168 memp = m; 00169 } else { 00170 memp_tab[i] = NULL; 00171 } 00172 } 00173 00174 #if !SYS_LIGHTWEIGHT_PROT 00175 mutex = sys_sem_new(1); 00176 #endif 00177 00178 00179 } |
Here is the call graph for this function:
|
Definition at line 182 of file memp.c. References DEBUGF, LWIP_ASSERT, MEM_ALIGN, MEMP_DEBUG, MEMP_MAX, memp_sizes, memp_tab, memp::next, NULL, u32_t, and u8_t. Referenced by memp_mallocp().
00183 { 00184 struct memp *memp; 00185 void *mem; 00186 00187 LWIP_ASSERT("memp_malloc: type < MEMP_MAX", type < MEMP_MAX); 00188 00189 memp = memp_tab[type]; 00190 00191 if(memp != NULL) { 00192 memp_tab[type] = memp->next; 00193 memp->next = NULL; 00194 #ifdef MEMP_STATS 00195 ++lwip_stats.memp[type].used; 00196 if(lwip_stats.memp[type].used > lwip_stats.memp[type].max) { 00197 lwip_stats.memp[type].max = lwip_stats.memp[type].used; 00198 } 00199 #endif /* MEMP_STATS */ 00200 LWIP_ASSERT("memp_malloc: memp properly aligned", 00201 ((u32_t)MEM_ALIGN((u8_t *)memp + sizeof(struct memp)) % MEM_ALIGNMENT) == 0); 00202 00203 mem = MEM_ALIGN((u8_t *)memp + sizeof(struct memp)); 00204 /* initialize memp memory with zeroes */ 00205 memset(mem, 0, memp_sizes[type]); 00206 return mem; 00207 } else { 00208 DEBUGF(MEMP_DEBUG | 2, ("memp_malloc: out of memory in pool %d\n", type)); 00209 #ifdef MEMP_STATS 00210 ++lwip_stats.memp[type].err; 00211 #endif /* MEMP_STATS */ 00212 return NULL; 00213 } 00214 } |
|
Definition at line 217 of file memp.c. References memp_malloc(), mutex, sys_sem_signal(), and sys_sem_wait(). Referenced by netbuf_new(), netconn_bind(), netconn_close(), netconn_connect(), netconn_delete(), netconn_disconnect(), netconn_listen(), netconn_new(), netconn_recv(), netconn_send(), netconn_write(), pbuf_alloc(), tcpip_apimsg(), tcpip_callback(), and tcpip_input().
00218 { 00219 void *mem; 00220 #if SYS_LIGHTWEIGHT_PROT 00221 SYS_ARCH_DECL_PROTECT(old_level); 00222 SYS_ARCH_PROTECT(old_level); 00223 #else /* SYS_LIGHTWEIGHT_PROT */ 00224 sys_sem_wait(mutex); 00225 #endif /* SYS_LIGHTWEIGHT_PROT */ 00226 00227 mem = memp_malloc(type); 00228 00229 #if SYS_LIGHTWEIGHT_PROT 00230 SYS_ARCH_UNPROTECT(old_level); 00231 #else /* SYS_LIGHTWEIGHT_PROT */ 00232 sys_sem_signal(mutex); 00233 #endif /* SYS_LIGHTWEIGHT_PROT */ 00234 return mem; 00235 } |
Here is the call graph for this function:
|
Definition at line 111 of file memp.c. Referenced by memp_init(). |
|
Initial value: { MEMP_NUM_PBUF, MEMP_NUM_UDP_PCB, MEMP_NUM_TCP_PCB, MEMP_NUM_TCP_PCB_LISTEN, MEMP_NUM_TCP_SEG, MEMP_NUM_NETBUF, MEMP_NUM_NETCONN, MEMP_NUM_API_MSG, MEMP_NUM_TCPIP_MSG } Definition at line 73 of file memp.c. Referenced by memp_init(). |
|
Initial value: { sizeof(struct pbuf), sizeof(struct udp_pcb), sizeof(struct tcp_pcb), sizeof(struct tcp_pcb_listen), sizeof(struct tcp_seg), sizeof(struct netbuf), sizeof(struct netconn), sizeof(struct api_msg), sizeof(struct tcpip_msg) } Definition at line 61 of file memp.c. Referenced by memp_init(), and memp_malloc(). |
|
Definition at line 59 of file memp.c. Referenced by memp_free(), memp_init(), and memp_malloc(). |
|
Definition at line 115 of file memp.c. Referenced by memp_freep(), memp_init(), and memp_mallocp(). |