[PATCH] score: Change _Heap_Extend() API

Sebastian Huber sebastian.huber at embedded-brains.de
Thu Aug 9 08:26:35 UTC 2012


Add _Heap_Extend_4() function which does the same as _Heap_Extend() and
has the signature of _Heap_Initialize().  The 4th parameter is ignored
(page size in _Heap_Initialize()).
---
 cpukit/rtems/src/regionextend.c         |    8 +++-----
 cpukit/score/include/rtems/score/heap.h |   23 +++++++++++++++++------
 cpukit/score/src/heapextend.c           |   26 ++++++++++++++++----------
 cpukit/score/src/pheapextend.c          |    7 +++----
 4 files changed, 39 insertions(+), 25 deletions(-)

diff --git a/cpukit/rtems/src/regionextend.c b/cpukit/rtems/src/regionextend.c
index cf4489e..7607451 100644
--- a/cpukit/rtems/src/regionextend.c
+++ b/cpukit/rtems/src/regionextend.c
@@ -46,7 +46,6 @@ rtems_status_code rtems_region_extend(
 )
 {
   uintptr_t           amount_extended;
-  bool                extend_ok;
   Objects_Locations   location;
   rtems_status_code   return_status;
   Region_Control     *the_region;
@@ -61,14 +60,13 @@ rtems_status_code rtems_region_extend(
 
       case OBJECTS_LOCAL:
 
-        extend_ok = _Heap_Extend(
+        amount_extended = _Heap_Extend(
           &the_region->Memory,
           starting_address,
-          length,
-          &amount_extended
+          length
         );
 
-        if ( extend_ok ) {
+        if ( amount_extended > 0 ) {
           the_region->length                += amount_extended;
           the_region->maximum_segment_size  += amount_extended;
           return_status = RTEMS_SUCCESSFUL;
diff --git a/cpukit/score/include/rtems/score/heap.h b/cpukit/score/include/rtems/score/heap.h
index 8e6220c..0904543 100644
--- a/cpukit/score/include/rtems/score/heap.h
+++ b/cpukit/score/include/rtems/score/heap.h
@@ -431,22 +431,33 @@ uintptr_t _Heap_Initialize(
  * @brief Extends the memory available for the heap @a heap using the memory
  * area starting at @a area_begin of size @a area_size bytes.
  *
- * The extended space available for allocation will be returned in
- * @a amount_extended.  This pointer may be @c NULL.
- *
  * There are no alignment requirements.  The memory area must be big enough to
  * contain some maintainance blocks.  It must not overlap parts of the current
  * heap areas.  Disconnected subordinate heap areas will lead to used blocks
  * which cover the gaps.  Extending with an inappropriate memory area will
  * corrupt the heap.
  *
- * Returns @c true in case of success, and @c false otherwise.
+ * Returns the extended space available for allocation, or zero in case of failure.
+ */
+uintptr_t _Heap_Extend(
+  Heap_Control *heap,
+  void *area_begin,
+  uintptr_t area_size
+);
+
+/**
+ * @brief Extends the memory available for the heap @a heap using the memory
+ * area starting at @a area_begin of size @a area_size bytes.
+ *
+ * This function provides the same signature as _Heap_Initialize().
+ *
+ * @see _Heap_Extend().
  */
-bool _Heap_Extend(
+uintptr_t _Heap_Extend_4(
   Heap_Control *heap,
   void *area_begin,
   uintptr_t area_size,
-  uintptr_t *amount_extended
+  uintptr_t unused
 );
 
 /**
diff --git a/cpukit/score/src/heapextend.c b/cpukit/score/src/heapextend.c
index 9d2d587..65e6482 100644
--- a/cpukit/score/src/heapextend.c
+++ b/cpukit/score/src/heapextend.c
@@ -108,11 +108,20 @@ static void _Heap_Link_above(
   last_block->size_and_flag |= HEAP_PREV_BLOCK_USED;
 }
 
-bool _Heap_Extend(
+uintptr_t _Heap_Extend_4(
+  Heap_Control *heap,
+  void *area_begin,
+  uintptr_t area_size,
+  uintptr_t unused
+)
+{
+  return _Heap_Extend( heap, area_begin, area_size );
+}
+
+uintptr_t _Heap_Extend(
   Heap_Control *heap,
   void *extend_area_begin_ptr,
-  uintptr_t extend_area_size,
-  uintptr_t *extended_size_ptr
+  uintptr_t extend_area_size
 )
 {
   Heap_Statistics *const stats = &heap->stats;
@@ -134,7 +143,7 @@ bool _Heap_Extend(
   bool extend_area_ok = false;
 
   if ( extend_area_end < extend_area_begin ) {
-    return false;
+    return 0;
   }
 
   extend_area_ok = _Heap_Get_first_and_last_block(
@@ -147,7 +156,7 @@ bool _Heap_Extend(
   );
   if (!extend_area_ok ) {
     /* For simplicity we reject extend areas that are too small */
-    return false;
+    return 0;
   }
 
   do {
@@ -160,7 +169,7 @@ bool _Heap_Extend(
     if (
       sub_area_end > extend_area_begin && extend_area_end > sub_area_begin
     ) {
-      return false;
+      return 0;
     }
 
     if ( extend_area_end == sub_area_begin ) {
@@ -234,8 +243,5 @@ bool _Heap_Extend(
   /* Statistics */
   stats->size += extended_size;
 
-  if ( extended_size_ptr != NULL )
-    *extended_size_ptr = extended_size;
-
-  return true;
+  return extended_size;
 }
diff --git a/cpukit/score/src/pheapextend.c b/cpukit/score/src/pheapextend.c
index be23c70..c39631c 100644
--- a/cpukit/score/src/pheapextend.c
+++ b/cpukit/score/src/pheapextend.c
@@ -28,12 +28,11 @@ bool _Protected_heap_Extend(
   uintptr_t     size
 )
 {
-  bool      extend_ok;
   uintptr_t amount_extended;
 
   _RTEMS_Lock_allocator();
-    extend_ok = _Heap_Extend(the_heap, starting_address, size, &amount_extended);
+    amount_extended = _Heap_Extend( the_heap, starting_address, size );
   _RTEMS_Unlock_allocator();
-  return extend_ok;
-}
 
+  return amount_extended != 0;
+}
-- 
1.7.7




More information about the devel mailing list