mirror of
https://github.com/apache/nuttx.git
synced 2026-05-27 11:26:12 +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:
@@ -97,7 +97,7 @@ static void mm_add_delaylist(struct mm_heap_s *heap, void *mem)
|
|||||||
#endif
|
#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;
|
bool ret = false;
|
||||||
#if defined(CONFIG_BUILD_FLAT) || defined(__KERNEL__)
|
#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);
|
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
|
* Name: mm_realloc
|
||||||
*
|
*
|
||||||
@@ -324,7 +340,7 @@ void *mm_realloc(struct mm_heap_s *heap, void *oldmem,
|
|||||||
int usmblks;
|
int usmblks;
|
||||||
int newsize;
|
int newsize;
|
||||||
|
|
||||||
mm_free_delaylist(heap, false);
|
free_delaylist(heap, false);
|
||||||
|
|
||||||
if (size == 0)
|
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));
|
while (atomic_compare_exchange_weak(&heap->usmblks, &usmblks, uordblks));
|
||||||
|
|
||||||
#if CONFIG_MM_FREE_DELAYCOUNT_MAX > 0
|
#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);
|
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 uordblks;
|
||||||
int usmblks;
|
int usmblks;
|
||||||
|
|
||||||
mm_free_delaylist(heap, false);
|
free_delaylist(heap, false);
|
||||||
mem = host_memalign(alignment, size);
|
mem = host_memalign(alignment, size);
|
||||||
|
|
||||||
if (mem == NULL)
|
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));
|
while (atomic_compare_exchange_weak(&heap->usmblks, &usmblks, uordblks));
|
||||||
|
|
||||||
#if CONFIG_MM_FREE_DELAYCOUNT_MAX > 0
|
#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);
|
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);
|
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 **************************************/
|
/* Functions contained in kmm_malloc.c **************************************/
|
||||||
|
|
||||||
#ifdef CONFIG_MM_KERNEL_HEAP
|
#ifdef CONFIG_MM_KERNEL_HEAP
|
||||||
|
|||||||
@@ -137,6 +137,22 @@ void mm_mempool_dump_handle(FAR struct mempool_s *pool, FAR void *arg)
|
|||||||
* Public Functions
|
* 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
|
* Name: mm_malloc
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -1447,3 +1447,19 @@ FAR void *mm_zalloc(FAR struct mm_heap_s *heap, size_t size)
|
|||||||
|
|
||||||
return alloc;
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user