You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by xi...@apache.org on 2024/08/02 17:30:11 UTC

(nuttx) 01/02: mm/mm.h: add mm_free_delaylist interface

This is an automated email from the ASF dual-hosted git repository.

xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git

commit cafee0e086f2d87a134648f20bb26b7646fd82ab
Author: Yanfeng Liu <yf...@qq.com>
AuthorDate: Fri Aug 2 12:00:07 2024 +0800

    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 <yf...@qq.com>
---
 arch/sim/src/sim/sim_heap.c | 26 +++++++++++++++++++++-----
 include/nuttx/mm/mm.h       |  2 ++
 mm/mm_heap/mm_malloc.c      | 16 ++++++++++++++++
 mm/tlsf/mm_tlsf.c           | 16 ++++++++++++++++
 4 files changed, 55 insertions(+), 5 deletions(-)

diff --git a/arch/sim/src/sim/sim_heap.c b/arch/sim/src/sim/sim_heap.c
index ac1828dcd8..5095bb5654 100644
--- a/arch/sim/src/sim/sim_heap.c
+++ b/arch/sim/src/sim/sim_heap.c
@@ -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);
     }
diff --git a/include/nuttx/mm/mm.h b/include/nuttx/mm/mm.h
index 63fd379adf..6ba6891176 100644
--- a/include/nuttx/mm/mm.h
+++ b/include/nuttx/mm/mm.h
@@ -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
diff --git a/mm/mm_heap/mm_malloc.c b/mm/mm_heap/mm_malloc.c
index fa980021ea..c6cde651eb 100644
--- a/mm/mm_heap/mm_malloc.c
+++ b/mm/mm_heap/mm_malloc.c
@@ -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
  *
diff --git a/mm/tlsf/mm_tlsf.c b/mm/tlsf/mm_tlsf.c
index 8e8d74dee9..98f2566bf9 100644
--- a/mm/tlsf/mm_tlsf.c
+++ b/mm/tlsf/mm_tlsf.c
@@ -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);
+    }
+}