Skip to content

Commit

Permalink
mm/mm.h: add mm_free_delaylist interface
Browse files Browse the repository at this point in the history
This adds explicit `void mm_free_delaylist(heap)` interface so that
to force freeing the heap's delaylist.

Signed-off-by: Yanfeng Liu <[email protected]>
  • Loading branch information
yf13 committed Aug 2, 2024
1 parent fe45d8a commit 3521952
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 5 deletions.
26 changes: 21 additions & 5 deletions arch/sim/src/sim/sim_heap.c
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ static void mm_add_delaylist(struct mm_heap_s *heap, void *mem)
#endif
}

static bool mm_free_delaylist(struct mm_heap_s *heap, bool force)
static bool free_delaylist(struct mm_heap_s *heap, bool force)
{
bool ret = false;
#if defined(CONFIG_BUILD_FLAT) || defined(__KERNEL__)
Expand Down Expand Up @@ -293,6 +293,22 @@ void mm_free(struct mm_heap_s *heap, void *mem)
mm_delayfree(heap, mem, CONFIG_MM_FREE_DELAYCOUNT_MAX > 0);
}

/****************************************************************************
* Name: mm_free_delaylist
*
* Description:
* force freeing the delaylist of this heap.
*
****************************************************************************/

void mm_free_delaylist(FAR struct mm_heap_s *heap)
{
if (heap)
{
free_delaylist(heap, true);
}
}

/****************************************************************************
* Name: mm_realloc
*
Expand Down Expand Up @@ -324,7 +340,7 @@ void *mm_realloc(struct mm_heap_s *heap, void *oldmem,
int usmblks;
int newsize;

mm_free_delaylist(heap, false);
free_delaylist(heap, false);

if (size == 0)
{
Expand All @@ -351,7 +367,7 @@ void *mm_realloc(struct mm_heap_s *heap, void *oldmem,
while (atomic_compare_exchange_weak(&heap->usmblks, &usmblks, uordblks));

#if CONFIG_MM_FREE_DELAYCOUNT_MAX > 0
if (mem == NULL && mm_free_delaylist(heap, true))
if (mem == NULL && free_delaylist(heap, true))
{
return mm_realloc(heap, oldmem, size);
}
Expand Down Expand Up @@ -420,7 +436,7 @@ void *mm_memalign(struct mm_heap_s *heap, size_t alignment, size_t size)
int uordblks;
int usmblks;

mm_free_delaylist(heap, false);
free_delaylist(heap, false);
mem = host_memalign(alignment, size);

if (mem == NULL)
Expand All @@ -444,7 +460,7 @@ void *mm_memalign(struct mm_heap_s *heap, size_t alignment, size_t size)
while (atomic_compare_exchange_weak(&heap->usmblks, &usmblks, uordblks));

#if CONFIG_MM_FREE_DELAYCOUNT_MAX > 0
if (mem == NULL && mm_free_delaylist(heap, true))
if (mem == NULL && free_delaylist(heap, true))
{
return mm_memalign(heap, alignment, size);
}
Expand Down
2 changes: 2 additions & 0 deletions include/nuttx/mm/mm.h
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,8 @@ void kmm_addregion(FAR void *heapstart, size_t heapsize);

FAR void *mm_malloc(FAR struct mm_heap_s *heap, size_t size) malloc_like1(2);

void mm_free_delaylist(FAR struct mm_heap_s *heap);

/* Functions contained in kmm_malloc.c **************************************/

#ifdef CONFIG_MM_KERNEL_HEAP
Expand Down
16 changes: 16 additions & 0 deletions mm/mm_heap/mm_malloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,22 @@ void mm_mempool_dump_handle(FAR struct mempool_s *pool, FAR void *arg)
* Public Functions
****************************************************************************/

/****************************************************************************
* Name: mm_free_delaylist
*
* Description:
* force freeing the delaylist of this heap.
*
****************************************************************************/

void mm_free_delaylist(FAR struct mm_heap_s *heap)
{
if (heap)
{
free_delaylist(heap, true);
}
}

/****************************************************************************
* Name: mm_malloc
*
Expand Down
16 changes: 16 additions & 0 deletions mm/tlsf/mm_tlsf.c
Original file line number Diff line number Diff line change
Expand Up @@ -1447,3 +1447,19 @@ FAR void *mm_zalloc(FAR struct mm_heap_s *heap, size_t size)

return alloc;
}

/****************************************************************************
* Name: mm_free_delaylist
*
* Description:
* force freeing the delaylist of this heap.
*
****************************************************************************/

void mm_free_delaylist(FAR struct mm_heap_s *heap)
{
if (heap)
{
free_delaylist(heap, true);
}
}

0 comments on commit 3521952

Please sign in to comment.