mirror of
https://github.com/apache/nuttx.git
synced 2025-01-13 09:49:21 +08:00
mm/mm.h: add mm_free_delaylist interface
This adds explicit `void mm_free_delaylist(heap)` interface so that to force freeing the heap's delaylist. Signed-off-by: Yanfeng Liu <yfliu2008@qq.com>
This commit is contained in:
parent
e9d20bd611
commit
cafee0e086
4 changed files with 55 additions and 5 deletions
|
@ -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__)
|
||||
|
@ -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
|
||||
*
|
||||
|
@ -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)
|
||||
{
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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)
|
||||
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
*
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue