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 2022/10/28 16:12:10 UTC
[incubator-nuttx] 03/03: mm/mm_heap: define MM_MASK_BIT as significant bits mask
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/incubator-nuttx.git
commit 579e47347e00d4439cb048265866ffd3f9c5b75a
Author: dongjiuzhu1 <do...@xiaomi.com>
AuthorDate: Tue Oct 25 22:52:02 2022 +0800
mm/mm_heap: define MM_MASK_BIT as significant bits mask
using MM_MASK_BIT to expand different bits of preceding field to store the
block status.
Signed-off-by: dongjiuzhu1 <do...@xiaomi.com>
---
mm/mm_heap/mm.h | 1 +
mm/mm_heap/mm_foreach.c | 2 +-
mm/mm_heap/mm_free.c | 10 +++++-----
mm/mm_heap/mm_malloc.c | 2 +-
mm/mm_heap/mm_memalign.c | 2 +-
mm/mm_heap/mm_realloc.c | 10 +++++-----
mm/mm_heap/mm_shrinkchunk.c | 5 +++--
7 files changed, 17 insertions(+), 15 deletions(-)
diff --git a/mm/mm_heap/mm.h b/mm/mm_heap/mm.h
index 65ee07cc56..9e908a38c3 100644
--- a/mm/mm_heap/mm.h
+++ b/mm/mm_heap/mm.h
@@ -114,6 +114,7 @@
*/
#define MM_ALLOC_BIT 0x1
+#define MM_MASK_BIT MM_ALLOC_BIT
#ifdef CONFIG_MM_SMALL
# define MMSIZE_MAX UINT16_MAX
#else
diff --git a/mm/mm_heap/mm_foreach.c b/mm/mm_heap/mm_foreach.c
index 70cf1579c0..9c86fd2dbb 100644
--- a/mm/mm_heap/mm_foreach.c
+++ b/mm/mm_heap/mm_foreach.c
@@ -86,7 +86,7 @@ void mm_foreach(FAR struct mm_heap_s *heap, mmchunk_handler_t handler,
handler(node, arg);
DEBUGASSERT(prev == NULL ||
- prev->size == (node->preceding & ~MM_ALLOC_BIT));
+ prev->size == (node->preceding & ~MM_MASK_BIT));
prev = node;
}
diff --git a/mm/mm_heap/mm_free.c b/mm/mm_heap/mm_free.c
index dcb89fe05f..d7d75d574b 100644
--- a/mm/mm_heap/mm_free.c
+++ b/mm/mm_heap/mm_free.c
@@ -107,12 +107,12 @@ void mm_free(FAR struct mm_heap_s *heap, FAR void *mem)
DEBUGASSERT(node->preceding & MM_ALLOC_BIT);
- node->preceding &= ~MM_ALLOC_BIT;
+ node->preceding &= ~MM_MASK_BIT;
/* Check if the following node is free and, if so, merge it */
next = (FAR struct mm_freenode_s *)((FAR char *)node + node->size);
- DEBUGASSERT((next->preceding & ~MM_ALLOC_BIT) == node->size);
+ DEBUGASSERT((next->preceding & ~MM_MASK_BIT) == node->size);
if ((next->preceding & MM_ALLOC_BIT) == 0)
{
FAR struct mm_allocnode_s *andbeyond;
@@ -140,7 +140,7 @@ void mm_free(FAR struct mm_heap_s *heap, FAR void *mem)
node->size += next->size;
andbeyond->preceding = node->size |
- (andbeyond->preceding & MM_ALLOC_BIT);
+ (andbeyond->preceding & MM_MASK_BIT);
next = (FAR struct mm_freenode_s *)andbeyond;
}
@@ -149,7 +149,7 @@ void mm_free(FAR struct mm_heap_s *heap, FAR void *mem)
*/
prev = (FAR struct mm_freenode_s *)((FAR char *)node - node->preceding);
- DEBUGASSERT((node->preceding & ~MM_ALLOC_BIT) == prev->size);
+ DEBUGASSERT((node->preceding & ~MM_MASK_BIT) == prev->size);
if ((prev->preceding & MM_ALLOC_BIT) == 0)
{
/* Remove the node. There must be a predecessor, but there may
@@ -166,7 +166,7 @@ void mm_free(FAR struct mm_heap_s *heap, FAR void *mem)
/* Then merge the two chunks */
prev->size += node->size;
- next->preceding = prev->size | (next->preceding & MM_ALLOC_BIT);
+ next->preceding = prev->size | (next->preceding & MM_MASK_BIT);
node = prev;
}
diff --git a/mm/mm_heap/mm_malloc.c b/mm/mm_heap/mm_malloc.c
index c1d52b23c9..0f1bb57808 100644
--- a/mm/mm_heap/mm_malloc.c
+++ b/mm/mm_heap/mm_malloc.c
@@ -221,7 +221,7 @@ FAR void *mm_malloc(FAR struct mm_heap_s *heap, size_t size)
* the allocated flag.
*/
- next->preceding = remaining | (next->preceding & MM_ALLOC_BIT);
+ next->preceding = remaining | (next->preceding & MM_MASK_BIT);
/* Add the remainder back into the nodelist */
diff --git a/mm/mm_heap/mm_memalign.c b/mm/mm_heap/mm_memalign.c
index 4608aa18c6..8e814fdf91 100644
--- a/mm/mm_heap/mm_memalign.c
+++ b/mm/mm_heap/mm_memalign.c
@@ -184,7 +184,7 @@ FAR void *mm_memalign(FAR struct mm_heap_s *heap, size_t alignment,
/* Reduce the size of the original chunk and mark it not allocated, */
node->size = precedingsize;
- node->preceding &= ~MM_ALLOC_BIT;
+ node->preceding &= ~MM_MASK_BIT;
/* Fix the preceding size of the next node */
diff --git a/mm/mm_heap/mm_realloc.c b/mm/mm_heap/mm_realloc.c
index 11a937a1a2..e45365fd1c 100644
--- a/mm/mm_heap/mm_realloc.c
+++ b/mm/mm_heap/mm_realloc.c
@@ -151,7 +151,7 @@ FAR void *mm_realloc(FAR struct mm_heap_s *heap, FAR void *oldmem,
}
prev = (FAR struct mm_freenode_s *)
- ((FAR char *)oldnode - (oldnode->preceding & ~MM_ALLOC_BIT));
+ ((FAR char *)oldnode - (oldnode->preceding & ~MM_MASK_BIT));
if ((prev->preceding & MM_ALLOC_BIT) == 0)
{
prevsize = prev->size;
@@ -253,7 +253,7 @@ FAR void *mm_realloc(FAR struct mm_heap_s *heap, FAR void *oldmem,
newnode->size = oldsize + takeprev;
newnode->preceding = prev->size | MM_ALLOC_BIT;
next->preceding = newnode->size |
- (next->preceding & MM_ALLOC_BIT);
+ (next->preceding & MM_MASK_BIT);
/* Return the previous free node to the nodelist
* (with the new size)
@@ -268,7 +268,7 @@ FAR void *mm_realloc(FAR struct mm_heap_s *heap, FAR void *oldmem,
newnode->size += oldsize;
newnode->preceding |= MM_ALLOC_BIT;
next->preceding = newnode->size |
- (next->preceding & MM_ALLOC_BIT);
+ (next->preceding & MM_MASK_BIT);
}
newmem = (FAR void *)((FAR char *)newnode + SIZEOF_MM_ALLOCNODE);
@@ -321,7 +321,7 @@ FAR void *mm_realloc(FAR struct mm_heap_s *heap, FAR void *oldmem,
DEBUGASSERT(newnode->size >= SIZEOF_MM_FREENODE);
newnode->preceding = oldnode->size;
andbeyond->preceding = newnode->size |
- (andbeyond->preceding & MM_ALLOC_BIT);
+ (andbeyond->preceding & MM_MASK_BIT);
/* Add the new free node to the nodelist (with the new size) */
@@ -332,7 +332,7 @@ FAR void *mm_realloc(FAR struct mm_heap_s *heap, FAR void *oldmem,
/* Yes, just update some pointers. */
andbeyond->preceding = oldnode->size |
- (andbeyond->preceding & MM_ALLOC_BIT);
+ (andbeyond->preceding & MM_MASK_BIT);
}
}
diff --git a/mm/mm_heap/mm_shrinkchunk.c b/mm/mm_heap/mm_shrinkchunk.c
index 1743e54687..5f57519440 100644
--- a/mm/mm_heap/mm_shrinkchunk.c
+++ b/mm/mm_heap/mm_shrinkchunk.c
@@ -95,7 +95,7 @@ void mm_shrinkchunk(FAR struct mm_heap_s *heap,
newnode->preceding = size;
node->size = size;
andbeyond->preceding = newnode->size |
- (andbeyond->preceding & MM_ALLOC_BIT);
+ (andbeyond->preceding & MM_MASK_BIT);
/* Add the new node to the freenodelist */
@@ -121,7 +121,8 @@ void mm_shrinkchunk(FAR struct mm_heap_s *heap,
newnode->size = node->size - size;
newnode->preceding = size;
node->size = size;
- next->preceding = newnode->size | MM_ALLOC_BIT;
+ next->preceding = newnode->size |
+ (next->preceding & MM_MASK_BIT);
/* Add the new node to the freenodelist */