mirror of
https://github.com/espressif/esp-nimble.git
synced 2026-09-28 11:47:23 +00:00
ESP-NimBLE: Allocate os_msys_init_1_data and os_msys_init_2_data dynamically
Allocating buffers dynamically and freeing when the job is done saves static memory
This commit is contained in:
committed by
Prasad Alatkar
parent
c2918bab25
commit
8ae95fa950
@@ -27,7 +27,7 @@
|
||||
#define SYSINIT_MSYS_1_MEMPOOL_SIZE \
|
||||
OS_MEMPOOL_SIZE(MYNEWT_VAL(MSYS_1_BLOCK_COUNT), \
|
||||
SYSINIT_MSYS_1_MEMBLOCK_SIZE)
|
||||
static os_membuf_t os_msys_init_1_data[SYSINIT_MSYS_1_MEMPOOL_SIZE];
|
||||
static os_membuf_t *os_msys_init_1_data;
|
||||
static struct os_mbuf_pool os_msys_init_1_mbuf_pool;
|
||||
static struct os_mempool os_msys_init_1_mempool;
|
||||
#endif
|
||||
@@ -38,7 +38,7 @@ static struct os_mempool os_msys_init_1_mempool;
|
||||
#define SYSINIT_MSYS_2_MEMPOOL_SIZE \
|
||||
OS_MEMPOOL_SIZE(MYNEWT_VAL(MSYS_2_BLOCK_COUNT), \
|
||||
SYSINIT_MSYS_2_MEMBLOCK_SIZE)
|
||||
static os_membuf_t os_msys_init_2_data[SYSINIT_MSYS_2_MEMPOOL_SIZE];
|
||||
static os_membuf_t *os_msys_init_2_data;
|
||||
static struct os_mbuf_pool os_msys_init_2_mbuf_pool;
|
||||
static struct os_mempool os_msys_init_2_mempool;
|
||||
#endif
|
||||
@@ -58,6 +58,41 @@ os_msys_init_once(void *data, struct os_mempool *mempool,
|
||||
assert(rc == 0);
|
||||
}
|
||||
|
||||
int
|
||||
os_msys_buf_alloc(void)
|
||||
{
|
||||
#if MYNEWT_VAL(MSYS_1_BLOCK_COUNT) > 0
|
||||
os_msys_init_1_data = (os_membuf_t *)calloc(1, (sizeof(os_membuf_t) * SYSINIT_MSYS_1_MEMPOOL_SIZE));
|
||||
if (!os_msys_init_1_data) {
|
||||
return -1;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if MYNEWT_VAL(MSYS_2_BLOCK_COUNT) > 0
|
||||
os_msys_init_2_data = (os_membuf_t *)calloc(1, (sizeof(os_membuf_t) * SYSINIT_MSYS_2_MEMPOOL_SIZE));
|
||||
if (!os_msys_init_2_data) {
|
||||
return -1;
|
||||
}
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
os_msys_buf_free(void)
|
||||
{
|
||||
#if MYNEWT_VAL(MSYS_1_BLOCK_COUNT) > 0
|
||||
free(os_msys_init_1_data);
|
||||
os_msys_init_1_data = NULL;
|
||||
#endif
|
||||
|
||||
#if MYNEWT_VAL(MSYS_2_BLOCK_COUNT) > 0
|
||||
free(os_msys_init_2_data);
|
||||
os_msys_init_2_data = NULL;
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
void
|
||||
os_msys_init(void)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user