mirror of
https://github.com/apache/nuttx.git
synced 2026-06-04 23:03:27 +08:00
mm: Remove mm_heap_impl_s struct
it's more simple to make mm_heap_s opaque outside of mm Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com> Change-Id: I5c8e435f6baba6d22b10c5f7e8d9191104fb5af2
This commit is contained in:
committed by
David Sidrane
parent
441b03c61c
commit
76cdd5c329
+38
-42
@@ -57,16 +57,13 @@
|
||||
void mm_addregion(FAR struct mm_heap_s *heap, FAR void *heapstart,
|
||||
size_t heapsize)
|
||||
{
|
||||
FAR struct mm_heap_impl_s *heap_impl;
|
||||
FAR struct mm_freenode_s *node;
|
||||
uintptr_t heapbase;
|
||||
uintptr_t heapend;
|
||||
#if CONFIG_MM_REGIONS > 1
|
||||
int IDX;
|
||||
|
||||
DEBUGASSERT(MM_IS_VALID(heap));
|
||||
heap_impl = heap->mm_impl;
|
||||
IDX = heap_impl->mm_nregions;
|
||||
IDX = heap->mm_nregions;
|
||||
|
||||
/* Writing past CONFIG_MM_REGIONS would have catastrophic consequences */
|
||||
|
||||
@@ -78,9 +75,6 @@ void mm_addregion(FAR struct mm_heap_s *heap, FAR void *heapstart,
|
||||
|
||||
#else
|
||||
# define IDX 0
|
||||
|
||||
DEBUGASSERT(MM_IS_VALID(heap));
|
||||
heap_impl = heap->mm_impl;
|
||||
#endif
|
||||
|
||||
#if defined(CONFIG_MM_SMALL) && !defined(CONFIG_SMALL_MEMORY)
|
||||
@@ -106,7 +100,7 @@ void mm_addregion(FAR struct mm_heap_s *heap, FAR void *heapstart,
|
||||
|
||||
/* Add the size of this region to the total size of the heap */
|
||||
|
||||
heap_impl->mm_heapsize += heapsize;
|
||||
heap->mm_heapsize += heapsize;
|
||||
|
||||
/* Create two "allocated" guard nodes at the beginning and end of
|
||||
* the heap. These only serve to keep us from allocating outside
|
||||
@@ -116,23 +110,23 @@ void mm_addregion(FAR struct mm_heap_s *heap, FAR void *heapstart,
|
||||
* all available memory.
|
||||
*/
|
||||
|
||||
heap_impl->mm_heapstart[IDX] = (FAR struct mm_allocnode_s *)
|
||||
heapbase;
|
||||
heap_impl->mm_heapstart[IDX]->size = SIZEOF_MM_ALLOCNODE;
|
||||
heap_impl->mm_heapstart[IDX]->preceding = MM_ALLOC_BIT;
|
||||
node = (FAR struct mm_freenode_s *)
|
||||
(heapbase + SIZEOF_MM_ALLOCNODE);
|
||||
node->size = heapsize - 2*SIZEOF_MM_ALLOCNODE;
|
||||
node->preceding = SIZEOF_MM_ALLOCNODE;
|
||||
heap_impl->mm_heapend[IDX] = (FAR struct mm_allocnode_s *)
|
||||
(heapend - SIZEOF_MM_ALLOCNODE);
|
||||
heap_impl->mm_heapend[IDX]->size = SIZEOF_MM_ALLOCNODE;
|
||||
heap_impl->mm_heapend[IDX]->preceding = node->size | MM_ALLOC_BIT;
|
||||
heap->mm_heapstart[IDX] = (FAR struct mm_allocnode_s *)
|
||||
heapbase;
|
||||
heap->mm_heapstart[IDX]->size = SIZEOF_MM_ALLOCNODE;
|
||||
heap->mm_heapstart[IDX]->preceding = MM_ALLOC_BIT;
|
||||
node = (FAR struct mm_freenode_s *)
|
||||
(heapbase + SIZEOF_MM_ALLOCNODE);
|
||||
node->size = heapsize - 2*SIZEOF_MM_ALLOCNODE;
|
||||
node->preceding = SIZEOF_MM_ALLOCNODE;
|
||||
heap->mm_heapend[IDX] = (FAR struct mm_allocnode_s *)
|
||||
(heapend - SIZEOF_MM_ALLOCNODE);
|
||||
heap->mm_heapend[IDX]->size = SIZEOF_MM_ALLOCNODE;
|
||||
heap->mm_heapend[IDX]->preceding = node->size | MM_ALLOC_BIT;
|
||||
|
||||
#undef IDX
|
||||
|
||||
#if CONFIG_MM_REGIONS > 1
|
||||
heap_impl->mm_nregions++;
|
||||
heap->mm_nregions++;
|
||||
#endif
|
||||
|
||||
/* Add the single, large free node to the nodelist */
|
||||
@@ -150,38 +144,38 @@ void mm_addregion(FAR struct mm_heap_s *heap, FAR void *heapstart,
|
||||
* heap region.
|
||||
*
|
||||
* Input Parameters:
|
||||
* name - The heap procfs name
|
||||
* heap - The selected heap
|
||||
* heapstart - Start of the initial heap region
|
||||
* heapsize - Size of the initial heap region
|
||||
*
|
||||
* Returned Value:
|
||||
* None
|
||||
* Return the address of a new heap instance.
|
||||
*
|
||||
* Assumptions:
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
void mm_initialize(FAR struct mm_heap_s *heap, FAR const char *name,
|
||||
FAR void *heapstart, size_t heapsize)
|
||||
FAR struct mm_heap_s *mm_initialize(FAR const char *name,
|
||||
FAR void *heapstart, size_t heapsize)
|
||||
{
|
||||
FAR struct mm_heap_impl_s *heap_impl;
|
||||
uintptr_t heap_adj;
|
||||
int i;
|
||||
FAR struct mm_heap_s *heap;
|
||||
uintptr_t heap_adj;
|
||||
int i;
|
||||
|
||||
minfo("Heap: name=%s, start=%p size=%zu\n", name, heapstart, heapsize);
|
||||
|
||||
/* First ensure the memory to be used is aligned */
|
||||
|
||||
heap_adj = MM_ALIGN_UP((uintptr_t) heapstart);
|
||||
heapsize -= heap_adj - (uintptr_t) heapstart;
|
||||
heap_adj = MM_ALIGN_UP((uintptr_t)heapstart);
|
||||
heapsize -= heap_adj - (uintptr_t)heapstart;
|
||||
|
||||
/* Reserve a block space for mm_heap_impl_s context */
|
||||
/* Reserve a block space for mm_heap_s context */
|
||||
|
||||
DEBUGASSERT(heapsize > sizeof(struct mm_heap_impl_s));
|
||||
heap->mm_impl = (FAR struct mm_heap_impl_s *)heap_adj;
|
||||
heap_impl = heap->mm_impl;
|
||||
heapsize -= sizeof(struct mm_heap_impl_s);
|
||||
heapstart = (FAR char *)heap_adj + sizeof(struct mm_heap_impl_s);
|
||||
DEBUGASSERT(heapsize > sizeof(struct mm_heap_s));
|
||||
heap = (FAR struct mm_heap_s *)heap_adj;
|
||||
heapsize -= sizeof(struct mm_heap_s);
|
||||
heapstart = (FAR char *)heap_adj + sizeof(struct mm_heap_s);
|
||||
|
||||
/* The following two lines have cause problems for some older ZiLog
|
||||
* compilers in the past (but not the more recent). Life is easier if we
|
||||
@@ -197,14 +191,14 @@ void mm_initialize(FAR struct mm_heap_s *heap, FAR const char *name,
|
||||
|
||||
/* Set up global variables */
|
||||
|
||||
memset(heap_impl, 0, sizeof(struct mm_heap_impl_s));
|
||||
memset(heap, 0, sizeof(struct mm_heap_s));
|
||||
|
||||
/* Initialize the node array */
|
||||
|
||||
for (i = 1; i < MM_NNODES; i++)
|
||||
{
|
||||
heap_impl->mm_nodelist[i - 1].flink = &heap_impl->mm_nodelist[i];
|
||||
heap_impl->mm_nodelist[i].blink = &heap_impl->mm_nodelist[i - 1];
|
||||
heap->mm_nodelist[i - 1].flink = &heap->mm_nodelist[i];
|
||||
heap->mm_nodelist[i].blink = &heap->mm_nodelist[i - 1];
|
||||
}
|
||||
|
||||
/* Initialize the malloc semaphore to one (to support one-at-
|
||||
@@ -219,10 +213,12 @@ void mm_initialize(FAR struct mm_heap_s *heap, FAR const char *name,
|
||||
|
||||
#if defined(CONFIG_FS_PROCFS) && !defined(CONFIG_FS_PROCFS_EXCLUDE_MEMINFO)
|
||||
#if defined(CONFIG_BUILD_FLAT) || defined(__KERNEL__)
|
||||
heap_impl->mm_procfs.name = name;
|
||||
heap_impl->mm_procfs.mallinfo = (FAR void *)mm_mallinfo;
|
||||
heap_impl->mm_procfs.user_data = heap;
|
||||
procfs_register_meminfo(&heap_impl->mm_procfs);
|
||||
heap->mm_procfs.name = name;
|
||||
heap->mm_procfs.mallinfo = (FAR void *)mm_mallinfo;
|
||||
heap->mm_procfs.user_data = heap;
|
||||
procfs_register_meminfo(&heap->mm_procfs);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
return heap;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user