From e25a7c461106dca2a8f1f5fb82fa25ef3f4c60c8 Mon Sep 17 00:00:00 2001 From: Marcin Szkudlinski Date: Fri, 11 Mar 2022 15:28:53 +0100 Subject: [PATCH] lib/mem_blocks: change internal alloc_one to alloc_blocks As preparation for memory blocks to support continuous memory blocks modify bitmap operation wrappers to support multiple bits alloc/free Signed-off-by: Marcin Szkudlinski --- lib/os/mem_blocks.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/os/mem_blocks.c b/lib/os/mem_blocks.c index 55969e3121..77d13d2656 100644 --- a/lib/os/mem_blocks.c +++ b/lib/os/mem_blocks.c @@ -11,7 +11,7 @@ #include #include -static void *alloc_one(sys_mem_blocks_t *mem_block) +static void *alloc_blocks(sys_mem_blocks_t *mem_block, size_t num_blocks) { size_t offset; int r; @@ -19,7 +19,7 @@ static void *alloc_one(sys_mem_blocks_t *mem_block) void *ret = NULL; /* Find an unallocated block */ - r = sys_bitarray_alloc(mem_block->bitmap, 1, &offset); + r = sys_bitarray_alloc(mem_block->bitmap, num_blocks, &offset); if (r != 0) { goto out; } @@ -33,7 +33,7 @@ out: return ret; } -static int free_one(sys_mem_blocks_t *mem_block, void *ptr) +static int free_blocks(sys_mem_blocks_t *mem_block, void *ptr, size_t num_blocks) { size_t offset; uint8_t *blk = ptr; @@ -51,7 +51,7 @@ static int free_one(sys_mem_blocks_t *mem_block, void *ptr) goto out; } - ret = sys_bitarray_free(mem_block->bitmap, 1, offset); + ret = sys_bitarray_free(mem_block->bitmap, num_blocks, offset); out: return ret; @@ -85,7 +85,7 @@ int sys_mem_blocks_alloc(sys_mem_blocks_t *mem_block, size_t count, } for (i = 0; i < count; i++) { - void *ptr = alloc_one(mem_block); + void *ptr = alloc_blocks(mem_block, 1); if (ptr == NULL) { break; @@ -138,7 +138,7 @@ int sys_mem_blocks_free(sys_mem_blocks_t *mem_block, size_t count, for (i = 0; i < count; i++) { void *ptr = in_blocks[i]; - int r = free_one(mem_block, ptr); + int r = free_blocks(mem_block, ptr, 1); if (r != 0) { ret = r;