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 2024/03/12 11:44:54 UTC

(nuttx) 01/02: mm_heap/mm.h: revising comments

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/nuttx.git

commit 813f67f93b29c2ca50d78e182f1e1dbdb6f609ae
Author: Yanfeng Liu <yf...@qq.com>
AuthorDate: Tue Mar 12 16:25:36 2024 +0800

    mm_heap/mm.h: revising comments
    
    Revising comments to be in line with code
    
    Signed-off-by: Yanfeng Liu <yf...@qq.com>
---
 mm/mm_heap/mm.h | 27 +++++++++++----------------
 1 file changed, 11 insertions(+), 16 deletions(-)

diff --git a/mm/mm_heap/mm.h b/mm/mm_heap/mm.h
index 67965686be..eb7809e638 100644
--- a/mm/mm_heap/mm.h
+++ b/mm/mm_heap/mm.h
@@ -121,8 +121,10 @@
 #define MM_ALIGN_UP(a)   (((a) + MM_GRAN_MASK) & ~MM_GRAN_MASK)
 #define MM_ALIGN_DOWN(a) ((a) & ~MM_GRAN_MASK)
 
-/* An allocated chunk is distinguished from a free chunk by bit 0
- * of the 'preceding' chunk size.  If set, then this is an allocated chunk.
+/* Due to alignment, the lowest two bits of valid chunk size are always
+ * zero, thus the two bits are reused to depict allocation status: bit
+ * 0 depicts the allocation state of current chunk, and bit 1 depicts that
+ * of the physically preceding chunk.
  */
 
 #define MM_ALLOC_BIT     0x1
@@ -169,14 +171,11 @@ typedef uint16_t mmsize_t;
 typedef size_t mmsize_t;
 #endif
 
-/* This describes an allocated chunk.  An allocated chunk is
- * distinguished from a free chunk by bit 15/31 of the 'preceding' chunk
- * size.  If set, then this is an allocated chunk.
- */
+/* This describes an allocated chunk */
 
 struct mm_allocnode_s
 {
-  mmsize_t preceding;                       /* Size of the preceding chunk */
+  mmsize_t preceding;                       /* Physical preceding chunk size */
   mmsize_t size;                            /* Size of this chunk */
 #if CONFIG_MM_BACKTRACE >= 0
   pid_t pid;                                /* The pid for caller */
@@ -191,7 +190,7 @@ struct mm_allocnode_s
 
 struct mm_freenode_s
 {
-  mmsize_t preceding;                       /* Size of the preceding chunk */
+  mmsize_t preceding;                       /* Physical preceding chunk size */
   mmsize_t size;                            /* Size of this chunk */
 #if CONFIG_MM_BACKTRACE >= 0
   pid_t pid;                                /* The pid for caller */
@@ -220,9 +219,7 @@ struct mm_delaynode_s
 
 struct mm_heap_s
 {
-  /* Mutually exclusive access to this data set is enforced with
-   * the following un-named mutex.
-   */
+  /* Mutex for controling access to this heap */
 
   mutex_t mm_lock;
 
@@ -238,7 +235,7 @@ struct mm_heap_s
 
   size_t mm_curused;
 
-  /* This is the first and last nodes of the heap */
+  /* The first and last allocated nodes of each region */
 
   FAR struct mm_allocnode_s *mm_heapstart[CONFIG_MM_REGIONS];
   FAR struct mm_allocnode_s *mm_heapend[CONFIG_MM_REGIONS];
@@ -249,14 +246,12 @@ struct mm_heap_s
 
   /* All free nodes are maintained in a doubly linked list.  This
    * array provides some hooks into the list at various points to
-   * speed searches for free nodes.
+   * speed up searching of free nodes.
    */
 
   struct mm_freenode_s mm_nodelist[MM_NNODES];
 
-  /* Free delay list, for some situations where we can't do free
-   * immdiately.
-   */
+  /* Free delay list, as sometimes we can't do free immdiately. */
 
   FAR struct mm_delaynode_s *mm_delaylist[CONFIG_SMP_NCPUS];