mirror of
https://github.com/espressif/esp-nimble.git
synced 2026-09-02 23:30:02 +00:00
Use allocation strategy for dynamic buffers in NimBLE host stack
This commit is contained in:
committed by
Abhinav Kudnar
parent
ea41bd0bdb
commit
3b44ea024d
@@ -20,6 +20,7 @@
|
||||
#include <stdlib.h>
|
||||
#include "os/os.h"
|
||||
#include "mem/mem.h"
|
||||
#include "esp_nimble_mem.h"
|
||||
|
||||
/**
|
||||
* Generic mempool allocation function. Used with basic and extended mempools.
|
||||
@@ -31,7 +32,7 @@ mem_malloc_mempool_gen(uint16_t num_blocks, uint32_t block_size,
|
||||
block_size = OS_ALIGN(block_size, OS_ALIGNMENT);
|
||||
|
||||
if (num_blocks > 0) {
|
||||
*out_buf = malloc(OS_MEMPOOL_BYTES(num_blocks, block_size));
|
||||
*out_buf = nimble_platform_mem_malloc(OS_MEMPOOL_BYTES(num_blocks, block_size));
|
||||
if (*out_buf == NULL) {
|
||||
return OS_ENOMEM;
|
||||
}
|
||||
@@ -72,7 +73,7 @@ mem_malloc_mempool(struct os_mempool *mempool, uint16_t num_blocks,
|
||||
|
||||
rc = os_mempool_init(mempool, num_blocks, block_size, buf, name);
|
||||
if (rc != 0) {
|
||||
free(buf);
|
||||
nimble_platform_mem_free(buf);
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -113,7 +114,7 @@ mem_malloc_mempool_ext(struct os_mempool_ext *mpe, uint16_t num_blocks,
|
||||
|
||||
rc = os_mempool_ext_init(mpe, num_blocks, block_size, buf, name);
|
||||
if (rc != 0) {
|
||||
free(buf);
|
||||
nimble_platform_mem_free(buf);
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -160,7 +161,7 @@ mem_malloc_mbuf_pool(struct os_mempool *mempool,
|
||||
|
||||
rc = os_mbuf_pool_init(mbuf_pool, mempool, block_size, num_blocks);
|
||||
if (rc != 0) {
|
||||
free(buf);
|
||||
nimble_platform_mem_free(buf);
|
||||
return rc;
|
||||
}
|
||||
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
#include "os/os.h"
|
||||
#include "mem/mem.h"
|
||||
#include "sysinit/sysinit.h"
|
||||
#include "esp_nimble_mem.h"
|
||||
|
||||
static STAILQ_HEAD(, os_mbuf_pool) g_msys_pool_list =
|
||||
STAILQ_HEAD_INITIALIZER(g_msys_pool_list);
|
||||
@@ -122,14 +123,14 @@ 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));
|
||||
os_msys_init_1_data = (os_membuf_t *)nimble_platform_mem_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));
|
||||
os_msys_init_2_data = (os_membuf_t *)nimble_platform_mem_calloc(1, (sizeof(os_membuf_t) * SYSINIT_MSYS_2_MEMPOOL_SIZE));
|
||||
if (!os_msys_init_2_data) {
|
||||
return -1;
|
||||
}
|
||||
@@ -142,12 +143,12 @@ void
|
||||
os_msys_buf_free(void)
|
||||
{
|
||||
#if MYNEWT_VAL(MSYS_1_BLOCK_COUNT) > 0
|
||||
free(os_msys_init_1_data);
|
||||
nimble_platform_mem_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);
|
||||
nimble_platform_mem_free(os_msys_init_2_data);
|
||||
os_msys_init_2_data = NULL;
|
||||
#endif
|
||||
|
||||
|
||||
Reference in New Issue
Block a user