mempool: Add k_mem_pool_free_id API
The k_mem_pool_free API has no use for the full k_mem_block struct. In particular, it only needs the k_mem_block_id. Introduce a new API which takes only this essential struct. This paves the way to simplify & improve the k_malloc/k_free implementation a bit. Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
This commit is contained in:
parent
af0bf06aa3
commit
7d887cb615
|
@ -3660,6 +3660,18 @@ extern int k_mem_pool_alloc(struct k_mem_pool *pool, struct k_mem_block *block,
|
|||
*/
|
||||
extern void k_mem_pool_free(struct k_mem_block *block);
|
||||
|
||||
/**
|
||||
* @brief Free memory allocated from a memory pool.
|
||||
*
|
||||
* This routine releases a previously allocated memory block back to its
|
||||
* memory pool
|
||||
*
|
||||
* @param id Memory block identifier.
|
||||
*
|
||||
* @return N/A
|
||||
*/
|
||||
extern void k_mem_pool_free_id(struct k_mem_block_id *id);
|
||||
|
||||
/**
|
||||
* @} end addtogroup mem_pool_apis
|
||||
*/
|
||||
|
|
|
@ -322,10 +322,10 @@ int k_mem_pool_alloc(struct k_mem_pool *p, struct k_mem_block *block,
|
|||
return -EAGAIN;
|
||||
}
|
||||
|
||||
void k_mem_pool_free(struct k_mem_block *block)
|
||||
void k_mem_pool_free_id(struct k_mem_block_id *id)
|
||||
{
|
||||
int i, key, need_sched = 0;
|
||||
struct k_mem_pool *p = get_pool(block->id.pool);
|
||||
struct k_mem_pool *p = get_pool(id->pool);
|
||||
size_t lsizes[p->n_levels];
|
||||
|
||||
/* As in k_mem_pool_alloc(), we build a table of level sizes
|
||||
|
@ -335,12 +335,11 @@ void k_mem_pool_free(struct k_mem_block *block)
|
|||
* sublevels.
|
||||
*/
|
||||
lsizes[0] = _ALIGN4(p->max_sz);
|
||||
for (i = 1; i <= block->id.level; i++) {
|
||||
for (i = 1; i <= id->level; i++) {
|
||||
lsizes[i] = _ALIGN4(lsizes[i-1] / 4);
|
||||
}
|
||||
|
||||
free_block(get_pool(block->id.pool), block->id.level,
|
||||
lsizes, block->id.block);
|
||||
free_block(get_pool(id->pool), id->level, lsizes, id->block);
|
||||
|
||||
/* Wake up anyone blocked on this pool and let them repeat
|
||||
* their allocation attempts
|
||||
|
@ -363,6 +362,11 @@ void k_mem_pool_free(struct k_mem_block *block)
|
|||
}
|
||||
}
|
||||
|
||||
void k_mem_pool_free(struct k_mem_block *block)
|
||||
{
|
||||
k_mem_pool_free_id(&block->id);
|
||||
}
|
||||
|
||||
#if (CONFIG_HEAP_MEM_POOL_SIZE > 0)
|
||||
|
||||
/*
|
||||
|
|
Loading…
Reference in a new issue