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/02/26 06:32:51 UTC
[incubator-nuttx] 01/06: mm/mm_heap: remove the unnecessary check for memory node size
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 39eaeefb78f36724adbdc47400d6f60372b68344
Author: Jiuzhu Dong <do...@xiaomi.com>
AuthorDate: Thu Jan 27 12:17:20 2022 +0800
mm/mm_heap: remove the unnecessary check for memory node size
Signed-off-by: Jiuzhu Dong <do...@xiaomi.com>
---
mm/mm_heap/mm.h | 37 +++++++++++++++++--------------------
mm/mm_heap/mm_initialize.c | 9 ---------
2 files changed, 17 insertions(+), 29 deletions(-)
diff --git a/mm/mm_heap/mm.h b/mm/mm_heap/mm.h
index 4726acb..1d7219d 100644
--- a/mm/mm_heap/mm.h
+++ b/mm/mm_heap/mm.h
@@ -29,6 +29,7 @@
#include <nuttx/fs/procfs.h>
+#include <assert.h>
#include <sys/types.h>
#include <stdbool.h>
#include <string.h>
@@ -103,12 +104,23 @@
#ifdef CONFIG_MM_SMALL
# define MM_ALLOC_BIT 0x8000
+# define MMSIZE_MAX UINT16_MAX
#else
# define MM_ALLOC_BIT 0x80000000
+# define MMSIZE_MAX UINT32_MAX
#endif
+
#define MM_IS_ALLOCATED(n) \
((int)((FAR struct mm_allocnode_s *)(n)->preceding) < 0)
+/* What is the size of the allocnode? */
+
+#define SIZEOF_MM_ALLOCNODE sizeof(struct mm_allocnode_s)
+
+/* What is the size of the freenode? */
+
+#define SIZEOF_MM_FREENODE sizeof(struct mm_freenode_s)
+
/****************************************************************************
* Public Types
****************************************************************************/
@@ -117,10 +129,8 @@
#ifdef CONFIG_MM_SMALL
typedef uint16_t mmsize_t;
-# define MMSIZE_MAX UINT16_MAX
#else
typedef uint32_t mmsize_t;
-# define MMSIZE_MAX UINT32_MAX
#endif
/* This describes an allocated chunk. An allocated chunk is
@@ -134,16 +144,8 @@ struct mm_allocnode_s
mmsize_t preceding; /* Size of the preceding chunk */
};
-/* What is the size of the allocnode? */
-
-#ifdef CONFIG_MM_SMALL
-# define SIZEOF_MM_ALLOCNODE (4)
-#else
-# define SIZEOF_MM_ALLOCNODE (8)
-#endif
-
-#define CHECK_ALLOCNODE_SIZE \
- DEBUGASSERT(sizeof(struct mm_allocnode_s) == SIZEOF_MM_ALLOCNODE)
+static_assert(SIZEOF_MM_ALLOCNODE <= MM_MIN_CHUNK,
+ "Error size for struct mm_allocnode_s\n");
/* This describes a free chunk */
@@ -155,19 +157,14 @@ struct mm_freenode_s
FAR struct mm_freenode_s *blink;
};
+static_assert(SIZEOF_MM_FREENODE <= MM_MIN_CHUNK,
+ "Error size for struct mm_freenode_s\n");
+
struct mm_delaynode_s
{
FAR struct mm_delaynode_s *flink;
};
-/* What is the size of the freenode? */
-
-#define MM_PTR_SIZE sizeof(FAR struct mm_freenode_s *)
-#define SIZEOF_MM_FREENODE (SIZEOF_MM_ALLOCNODE + 2*MM_PTR_SIZE)
-
-#define CHECK_FREENODE_SIZE \
- DEBUGASSERT(sizeof(struct mm_freenode_s) == SIZEOF_MM_FREENODE)
-
/* This describes one heap (possibly with multiple regions) */
struct mm_heap_s
diff --git a/mm/mm_heap/mm_initialize.c b/mm/mm_heap/mm_initialize.c
index 4e2a21b..bf84db4 100644
--- a/mm/mm_heap/mm_initialize.c
+++ b/mm/mm_heap/mm_initialize.c
@@ -182,15 +182,6 @@ FAR struct mm_heap_s *mm_initialize(FAR const char *name,
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
- * just the suppress them altogther for those tools.
- */
-
-#ifndef __ZILOG__
- CHECK_ALLOCNODE_SIZE;
- CHECK_FREENODE_SIZE;
-#endif
DEBUGASSERT(MM_MIN_CHUNK >= SIZEOF_MM_FREENODE);
DEBUGASSERT(MM_MIN_CHUNK >= SIZEOF_MM_ALLOCNODE);