mempool: reverse free bit semantic

This turns the free-bit flag into an alloc-bit flag effectively
reversing its semantic. This is to make further changes more natural
and easier to understand.

No need to clear the alloc bits at init time as they're located in .bss
and all clear already.

The code remains functionally equivalent after this change.

Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
This commit is contained in:
Nicolas Pitre 2019-10-03 14:56:11 -04:00 committed by Anas Nashif
parent 89e97d13ec
commit 1b193e9ece
1 changed files with 9 additions and 10 deletions

View File

@ -40,7 +40,7 @@ static int get_bit_ptr(struct sys_mem_pool_base *p, int level, int bn,
return bn & 0x1f;
}
static void set_free_bit(struct sys_mem_pool_base *p, int level, int bn)
static void set_alloc_bit(struct sys_mem_pool_base *p, int level, int bn)
{
u32_t *word;
int bit = get_bit_ptr(p, level, bn, &word);
@ -48,7 +48,7 @@ static void set_free_bit(struct sys_mem_pool_base *p, int level, int bn)
*word |= (1<<bit);
}
static void clear_free_bit(struct sys_mem_pool_base *p, int level, int bn)
static void clear_alloc_bit(struct sys_mem_pool_base *p, int level, int bn)
{
u32_t *word;
int bit = get_bit_ptr(p, level, bn, &word);
@ -56,10 +56,10 @@ static void clear_free_bit(struct sys_mem_pool_base *p, int level, int bn)
*word &= ~(1<<bit);
}
/* Returns all four of the free bits for the specified blocks
/* Returns all four of the allocated bits for the specified blocks
* "partners" in the bottom 4 bits of the return value
*/
static int partner_bits(struct sys_mem_pool_base *p, int level, int bn)
static int partner_alloc_bits(struct sys_mem_pool_base *p, int level, int bn)
{
u32_t *word;
int bit = get_bit_ptr(p, level, bn, &word);
@ -94,7 +94,6 @@ void z_sys_mem_pool_base_init(struct sys_mem_pool_base *p)
void *block = block_ptr(p, p->max_sz, i);
sys_dlist_append(&p->levels[0].free_list, block);
set_free_bit(p, 0, i);
}
}
@ -138,7 +137,7 @@ static void *block_alloc(struct sys_mem_pool_base *p, int l, size_t lsz)
block = sys_dlist_get(&p->levels[l].free_list);
if (block != NULL) {
clear_free_bit(p, l, block_num(p, block, lsz));
set_alloc_bit(p, l, block_num(p, block, lsz));
}
return block;
}
@ -152,7 +151,7 @@ static unsigned int bfree_recombine(struct sys_mem_pool_base *p, int level,
void *block = block_ptr(p, lsz, bn);
/* Put it back */
set_free_bit(p, level, bn);
clear_alloc_bit(p, level, bn);
sys_dlist_append(&p->levels[level].free_list, block);
/* Relax the lock (might result in it being taken, which is OK!) */
@ -160,14 +159,14 @@ static unsigned int bfree_recombine(struct sys_mem_pool_base *p, int level,
key = pool_irq_lock(p);
/* Check if we can recombine its superblock, and repeat */
if (level == 0 || partner_bits(p, level, bn) != 0xf) {
if (level == 0 || partner_alloc_bits(p, level, bn) != 0) {
return key;
}
for (i = 0; i < 4; i++) {
int b = (bn & ~3) + i;
clear_free_bit(p, level, b);
set_alloc_bit(p, level, b);
sys_dlist_remove(block_ptr(p, lsz, b));
}
@ -205,7 +204,7 @@ static void *block_break(struct sys_mem_pool_base *p, void *block, int l,
int lsz = lsizes[l + 1];
void *block2 = (lsz * i) + (char *)block;
set_free_bit(p, l + 1, lbn);
clear_alloc_bit(p, l + 1, lbn);
sys_dlist_append(&p->levels[l + 1].free_list, block2);
}