Skip to content

Commit

Permalink
mm: Add mm_uninitialize to release the resource
Browse files Browse the repository at this point in the history
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
  • Loading branch information
xiaoxiang781216 authored and masayuki2009 committed Jun 12, 2022
1 parent 7c12e52 commit 53c6789
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 6 deletions.
24 changes: 24 additions & 0 deletions fs/procfs/fs_procfsmeminfo.c
Expand Up @@ -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 */
13 changes: 13 additions & 0 deletions include/nuttx/fs/procfs.h
Expand Up @@ -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
}
Expand Down
1 change: 1 addition & 0 deletions include/nuttx/mm/mm.h
Expand Up @@ -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 **********************************/

Expand Down
1 change: 1 addition & 0 deletions mm/mm_heap/mm.h
Expand Up @@ -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);

Expand Down
36 changes: 30 additions & 6 deletions mm/mm_heap/mm_initialize.c
Expand Up @@ -217,24 +217,48 @@ 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 */

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);
}
15 changes: 15 additions & 0 deletions mm/mm_heap/mm_sem.c
Expand Up @@ -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
*
Expand Down

0 comments on commit 53c6789

Please sign in to comment.