memp: cleaned up MEMP_MEM_MALLOC:

- support memp stats when MEMP_MEM_MALLOC==1 (bug #48442);
- hide MEMP_MEM_MALLOC in memp.c instead of messing up the header file;
- make MEMP_OVERFLOW_CHECK work when MEMP_MEM_MALLOC==1
This commit is contained in:
sg
2016-07-21 22:17:32 +02:00
parent 413eeef5fa
commit de9054cb7a
6 changed files with 208 additions and 154 deletions

View File

@@ -60,21 +60,14 @@ extern const struct memp_desc* const memp_pools[MEMP_MAX];
#if MEMP_MEM_MALLOC
#include "lwip/mem.h"
#define memp_init()
#define memp_malloc(type) mem_malloc(memp_pools[type]->size)
#define memp_free(type, mem) mem_free(mem)
#define LWIP_MEMPOOL_DECLARE(name,num,size,desc) \
LWIP_MEMPOOL_DECLARE_STATS_INSTANCE(memp_stats_ ## name) \
const struct memp_desc memp_ ## name = { \
DECLARE_LWIP_MEMPOOL_DESC(desc) \
LWIP_MEMPOOL_DECLARE_STATS_REFERENCE(memp_stats_ ## name) \
LWIP_MEM_ALIGN_SIZE(size) \
};
#define LWIP_MEMPOOL_INIT(name)
#define LWIP_MEMPOOL_ALLOC(name) mem_malloc(memp_ ## name.size)
#define LWIP_MEMPOOL_FREE(name, x) mem_free(x)
#else /* MEMP_MEM_MALLOC */
/** Declare a private memory pool
@@ -102,14 +95,16 @@ extern const struct memp_desc* const memp_pools[MEMP_MAX];
static struct memp *memp_tab_ ## name; \
\
const struct memp_desc memp_ ## name = { \
LWIP_MEM_ALIGN_SIZE(size), \
LWIP_MEMPOOL_DECLARE_STATS_REFERENCE(memp_stats_ ## name) \
(num), \
DECLARE_LWIP_MEMPOOL_DESC(desc) \
LWIP_MEMPOOL_DECLARE_STATS_REFERENCE(memp_stats_ ## name) \
LWIP_MEM_ALIGN_SIZE(size), \
(num), \
memp_memory_ ## name ## _base, \
&memp_tab_ ## name \
};
#endif /* MEMP_MEM_MALLOC */
/** Initialize a private memory pool */
#define LWIP_MEMPOOL_INIT(name) memp_init_pool(&memp_ ## name)
/** Allocate from a private memory pool */
@@ -139,8 +134,6 @@ void *memp_malloc(memp_t type);
#endif
void memp_free(memp_t type, void *mem);
#endif /* MEMP_MEM_MALLOC */
#ifdef __cplusplus
}
#endif

View File

@@ -87,6 +87,7 @@ extern "C" {
#endif /* MEMP_OVERFLOW_CHECK */
#if !MEMP_MEM_MALLOC || MEMP_OVERFLOW_CHECK
struct memp {
struct memp *next;
#if MEMP_OVERFLOW_CHECK
@@ -94,6 +95,7 @@ struct memp {
int line;
#endif /* MEMP_OVERFLOW_CHECK */
};
#endif /* !MEMP_MEM_MALLOC || MEMP_OVERFLOW_CHECK */
#if MEM_USE_POOLS
/* Use a helper type to get the start and end of the user "memory pools" for mem_malloc */
@@ -126,23 +128,22 @@ typedef enum {
/** Memory pool descriptor */
struct memp_desc {
/** Element size */
u16_t size;
#if defined(LWIP_DEBUG) || MEMP_OVERFLOW_CHECK || LWIP_STATS_DISPLAY
/** Textual description */
const char *desc;
#endif /* LWIP_DEBUG || MEMP_OVERFLOW_CHECK || LWIP_STATS_DISPLAY */
#if MEMP_STATS
/** Statistics */
struct stats_mem *stats;
#endif
/** Element size */
u16_t size;
#if !MEMP_MEM_MALLOC
/** Number of elements */
u16_t num;
#if defined(LWIP_DEBUG) || MEMP_OVERFLOW_CHECK || LWIP_STATS_DISPLAY
/** Textual description */
const char *desc;
#endif /* LWIP_DEBUG || MEMP_OVERFLOW_CHECK || LWIP_STATS_DISPLAY */
/** Base address */
u8_t *base;

View File

@@ -1,6 +1,9 @@
/**
* @file
* lwIP internal memory pools (do not use in application code)
* This file is deliberately included multiple times: once with empty
* definition of LWIP_MEMPOOL() to handle all includes and multiple times
* to build up various lists of mem pools.
*/
/*