[rtems commit] confdefs.h: Fix heap alloc size estimate

Sebastian Huber sebh at rtems.org
Wed May 25 10:45:37 UTC 2016


Module:    rtems
Branch:    master
Commit:    25e28d84d75bf4a3d2388cb3aff904c90122ddad
Changeset: http://git.rtems.org/rtems/commit/?id=25e28d84d75bf4a3d2388cb3aff904c90122ddad

Author:    Sebastian Huber <sebastian.huber at embedded-brains.de>
Date:      Tue May 24 09:43:28 2016 +0200

confdefs.h: Fix heap alloc size estimate

Account for the heap minimum block size.

---

 cpukit/sapi/include/confdefs.h | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/cpukit/sapi/include/confdefs.h b/cpukit/sapi/include/confdefs.h
index 95f29fd..d35aaa4 100644
--- a/cpukit/sapi/include/confdefs.h
+++ b/cpukit/sapi/include/confdefs.h
@@ -1369,10 +1369,13 @@ extern rtems_initialization_tasks_table Initialization_tasks[];
 #define _Configure_Zero_or_One(_number) ((_number) ? 1 : 0)
 
 /**
- * General helper to aligned a value up to a power of two boundary.
+ * General helper to align up a value.
  */
 #define _Configure_Align_up(_val, _align) \
-  (((_val) + (_align) - 1) & ~((_align) - 1))
+  (((_val) + (_align) - 1) - ((_val) + (_align) - 1) % (_align))
+
+#define CONFIGURE_HEAP_MIN_BLOCK_SIZE \
+  _Configure_Align_up(sizeof(Heap_Block), CPU_HEAP_ALIGNMENT)
 
 /**
  * This is a helper macro used in calculations in this file.  It is used
@@ -1381,8 +1384,9 @@ extern rtems_initialization_tasks_table Initialization_tasks[];
  * may be applied.
  */
 #define _Configure_From_workspace(_size) \
-   (ssize_t) (_Configure_Zero_or_One(_size) * \
-     _Configure_Align_up((_size) + HEAP_BLOCK_HEADER_SIZE, CPU_HEAP_ALIGNMENT))
+  (ssize_t) (_Configure_Zero_or_One(_size) * \
+    _Configure_Align_up(_size + HEAP_BLOCK_HEADER_SIZE, \
+      CONFIGURE_HEAP_MIN_BLOCK_SIZE))
 
 /**
  * This is a helper macro used in stack space calculations in this file.  It




More information about the vc mailing list