Skip to content

Commit 069112d

Browse files
authored
Merge pull request #5 from mtnofcode/block-size-is-rounded-size
Change mapping() to take a pointer to the size
2 parents 564ee49 + 1ccadf1 commit 069112d

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

tlsf.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -463,14 +463,14 @@ static void arena_shrink(tlsf_t *t, tlsf_block_t *block)
463463
}
464464
}
465465

466-
INLINE tlsf_block_t *block_find_free(tlsf_t *t, size_t size)
466+
INLINE tlsf_block_t *block_find_free(tlsf_t *t, size_t *size)
467467
{
468-
size_t rounded = round_block_size(size);
468+
*size = round_block_size(*size);
469469
uint32_t fl, sl;
470-
mapping(rounded, &fl, &sl);
470+
mapping(*size, &fl, &sl);
471471
tlsf_block_t *block = block_find_suitable(t, &fl, &sl);
472472
if (UNLIKELY(!block)) {
473-
if (!arena_grow(t, rounded))
473+
if (!arena_grow(t, *size))
474474
return NULL;
475475
block = block_find_suitable(t, &fl, &sl);
476476
ASSERT(block, "no block found");
@@ -485,7 +485,7 @@ void *tlsf_malloc(tlsf_t *t, size_t size)
485485
size = adjust_size(size, ALIGN_SIZE);
486486
if (UNLIKELY(size > TLSF_MAX_SIZE))
487487
return NULL;
488-
tlsf_block_t *block = block_find_free(t, size);
488+
tlsf_block_t *block = block_find_free(t, &size);
489489
if (UNLIKELY(!block))
490490
return NULL;
491491
return block_use(t, block, size);
@@ -507,7 +507,7 @@ void *tlsf_aalloc(tlsf_t *t, size_t align, size_t size)
507507

508508
size_t asize =
509509
adjust_size(adjust + align - 1 + sizeof(tlsf_block_t), align);
510-
tlsf_block_t *block = block_find_free(t, asize);
510+
tlsf_block_t *block = block_find_free(t, &asize);
511511
if (UNLIKELY(!block))
512512
return NULL;
513513

0 commit comments

Comments
 (0)