You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by ma...@apache.org on 2022/06/12 10:41:19 UTC
[incubator-nuttx] branch master updated: mm: Add mm_uninitialize to release the resource
This is an automated email from the ASF dual-hosted git repository.
masayuki pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git
The following commit(s) were added to refs/heads/master by this push:
new 53c6789bef mm: Add mm_uninitialize to release the resource
53c6789bef is described below
commit 53c6789bef5951525acc81464e9d97d2436717ee
Author: Xiang Xiao <xi...@xiaomi.com>
AuthorDate: Fri Jun 10 09:47:41 2022 +0800
mm: Add mm_uninitialize to release the resource
Signed-off-by: Xiang Xiao <xi...@xiaomi.com>
---
fs/procfs/fs_procfsmeminfo.c | 24 ++++++++++++++++++++++++
include/nuttx/fs/procfs.h | 13 +++++++++++++
include/nuttx/mm/mm.h | 1 +
mm/mm_heap/mm.h | 1 +
mm/mm_heap/mm_initialize.c | 36 ++++++++++++++++++++++++++++++------
mm/mm_heap/mm_sem.c | 15 +++++++++++++++
6 files changed, 84 insertions(+), 6 deletions(-)
diff --git a/fs/procfs/fs_procfsmeminfo.c b/fs/procfs/fs_procfsmeminfo.c
index 1a8c66b89b..59a1803080 100644
--- a/fs/procfs/fs_procfsmeminfo.c
+++ b/fs/procfs/fs_procfsmeminfo.c
@@ -582,4 +582,28 @@ void procfs_register_meminfo(FAR struct procfs_meminfo_entry_s *entry)
g_procfs_meminfo = entry;
}
+/****************************************************************************
+ * Name: procfs_unregister_meminfo
+ *
+ * Description:
+ * Remove a meminfo entry from the procfs file system.
+ *
+ * Input Parameters:
+ * entry - Describes the entry to be unregistered.
+ *
+ ****************************************************************************/
+
+void procfs_unregister_meminfo(FAR struct procfs_meminfo_entry_s *entry)
+{
+ FAR struct procfs_meminfo_entry_s **cur;
+
+ for (cur = &g_procfs_meminfo; *cur != NULL; cur = &(*cur)->next)
+ {
+ if (*cur == entry)
+ {
+ *cur = entry->next;
+ break;
+ }
+ }
+}
#endif /* !CONFIG_FS_PROCFS_EXCLUDE_MEMINFO */
diff --git a/include/nuttx/fs/procfs.h b/include/nuttx/fs/procfs.h
index 97bd245f08..8d7d840e7d 100644
--- a/include/nuttx/fs/procfs.h
+++ b/include/nuttx/fs/procfs.h
@@ -256,6 +256,19 @@ int procfs_register(FAR const struct procfs_entry_s *entry);
void procfs_register_meminfo(FAR struct procfs_meminfo_entry_s *entry);
+/****************************************************************************
+ * Name: procfs_unregister_meminfo
+ *
+ * Description:
+ * Remove a meminfo entry from the procfs file system.
+ *
+ * Input Parameters:
+ * entry - Describes the entry to be unregistered.
+ *
+ ****************************************************************************/
+
+void procfs_unregister_meminfo(FAR struct procfs_meminfo_entry_s *entry);
+
#undef EXTERN
#ifdef __cplusplus
}
diff --git a/include/nuttx/mm/mm.h b/include/nuttx/mm/mm.h
index d7dc01175b..2024ea8830 100644
--- a/include/nuttx/mm/mm.h
+++ b/include/nuttx/mm/mm.h
@@ -156,6 +156,7 @@ FAR struct mm_heap_s *mm_initialize(FAR const char *name,
FAR void *heap_start, size_t heap_size);
void mm_addregion(FAR struct mm_heap_s *heap, FAR void *heapstart,
size_t heapsize);
+void mm_uninitialize(FAR struct mm_heap_s *heap);
/* Functions contained in umm_initialize.c **********************************/
diff --git a/mm/mm_heap/mm.h b/mm/mm_heap/mm.h
index ba2e589af6..8360069efe 100644
--- a/mm/mm_heap/mm.h
+++ b/mm/mm_heap/mm.h
@@ -251,6 +251,7 @@ typedef CODE void (*mmchunk_handler_t)(FAR struct mm_allocnode_s *node,
/* Functions contained in mm_sem.c ******************************************/
void mm_seminitialize(FAR struct mm_heap_s *heap);
+void mm_semuninitialize(FAR struct mm_heap_s *heap);
bool mm_takesemaphore(FAR struct mm_heap_s *heap);
void mm_givesemaphore(FAR struct mm_heap_s *heap);
diff --git a/mm/mm_heap/mm_initialize.c b/mm/mm_heap/mm_initialize.c
index 69d81732e4..4ef51c1433 100644
--- a/mm/mm_heap/mm_initialize.c
+++ b/mm/mm_heap/mm_initialize.c
@@ -217,13 +217,13 @@ FAR struct mm_heap_s *mm_initialize(FAR const char *name,
mm_seminitialize(heap);
#if defined(CONFIG_FS_PROCFS) && !defined(CONFIG_FS_PROCFS_EXCLUDE_MEMINFO)
-#if defined(CONFIG_BUILD_FLAT) || defined(__KERNEL__)
+# if defined(CONFIG_BUILD_FLAT) || defined(__KERNEL__)
heap->mm_procfs.name = name;
heap->mm_procfs.heap = heap;
-#if defined (CONFIG_DEBUG_MM) && defined(CONFIG_MM_BACKTRACE_DEFAULT)
+# if defined (CONFIG_DEBUG_MM) && defined(CONFIG_MM_BACKTRACE_DEFAULT)
heap->mm_procfs.backtrace = true;
-#endif
-#endif
+# endif
+# endif
#endif
/* Add the initial region of memory to the heap */
@@ -231,10 +231,34 @@ FAR struct mm_heap_s *mm_initialize(FAR const char *name,
mm_addregion(heap, heapstart, heapsize);
#if defined(CONFIG_FS_PROCFS) && !defined(CONFIG_FS_PROCFS_EXCLUDE_MEMINFO)
-#if defined(CONFIG_BUILD_FLAT) || defined(__KERNEL__)
+# if defined(CONFIG_BUILD_FLAT) || defined(__KERNEL__)
procfs_register_meminfo(&heap->mm_procfs);
-#endif
+# endif
#endif
return heap;
}
+
+/****************************************************************************
+ * Name: mm_uninitialize
+ *
+ * Description:
+ * Uninitialize the selected heap data structures.
+ *
+ * Input Parameters:
+ * heap - The heap to uninitialize
+ *
+ * Returned Value:
+ * None
+ *
+ ****************************************************************************/
+
+void mm_uninitialize(FAR struct mm_heap_s *heap)
+{
+#if defined(CONFIG_FS_PROCFS) && !defined(CONFIG_FS_PROCFS_EXCLUDE_MEMINFO)
+# if defined(CONFIG_BUILD_FLAT) || defined(__KERNEL__)
+ procfs_unregister_meminfo(&heap->mm_procfs);
+# endif
+#endif
+ mm_semuninitialize(heap);
+}
diff --git a/mm/mm_heap/mm_sem.c b/mm/mm_heap/mm_sem.c
index f73a5b40cc..a60c91a7d5 100644
--- a/mm/mm_heap/mm_sem.c
+++ b/mm/mm_heap/mm_sem.c
@@ -56,6 +56,21 @@ void mm_seminitialize(FAR struct mm_heap_s *heap)
_SEM_INIT(&heap->mm_semaphore, 0, 1);
}
+/****************************************************************************
+ * Name: mm_seminitialize
+ *
+ * Description:
+ * Uninitialize the MM mutex
+ *
+ ****************************************************************************/
+
+void mm_semuninitialize(FAR struct mm_heap_s *heap)
+{
+ /* Uninitialize the MM semaphore */
+
+ _SEM_DESTROY(&heap->mm_semaphore);
+}
+
/****************************************************************************
* Name: mm_takesemaphore
*