[rtems commit] score: _Heap_Protection_free_all_delayed_blocks()

Sebastian Huber sebh at rtems.org
Fri Jun 21 08:23:25 UTC 2013


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

Author:    Sebastian Huber <sebastian.huber at embedded-brains.de>
Date:      Fri Jun 21 09:16:19 2013 +0200

score: _Heap_Protection_free_all_delayed_blocks()

Add and use _Heap_Protection_free_all_delayed_blocks() to prevent
test suite failures if RTEMS_DEBUG is defined.

---

 cpukit/libcsupport/src/resource_snapshot.c |   14 ++++++++++++++
 cpukit/score/include/rtems/score/heap.h    |   11 +++++++++++
 cpukit/score/src/heapgreedy.c              |    2 ++
 3 files changed, 27 insertions(+), 0 deletions(-)

diff --git a/cpukit/libcsupport/src/resource_snapshot.c b/cpukit/libcsupport/src/resource_snapshot.c
index e143fdf..1ac9e63 100644
--- a/cpukit/libcsupport/src/resource_snapshot.c
+++ b/cpukit/libcsupport/src/resource_snapshot.c
@@ -85,11 +85,25 @@ static int open_files(void)
   return (int) rtems_libio_number_iops - free_count;
 }
 
+static void free_all_delayed_blocks(void)
+{
+  #ifdef HEAP_PROTECTION
+    _RTEMS_Lock_allocator();
+    _Thread_Disable_dispatch();
+    _Heap_Protection_free_all_delayed_blocks( RTEMS_Malloc_Heap );
+    _Heap_Protection_free_all_delayed_blocks( &_Workspace_Area );
+    _Thread_Enable_dispatch();
+    _RTEMS_Unlock_allocator();
+  #endif
+}
+
 void rtems_resource_snapshot_take(rtems_resource_snapshot *snapshot)
 {
   uint32_t *active = &snapshot->rtems_api.active_barriers;
   size_t i;
 
+  free_all_delayed_blocks();
+
   _Protected_heap_Get_information(RTEMS_Malloc_Heap, &snapshot->heap_info);
 
   _Thread_Disable_dispatch();
diff --git a/cpukit/score/include/rtems/score/heap.h b/cpukit/score/include/rtems/score/heap.h
index 80b3fd2..2937490 100644
--- a/cpukit/score/include/rtems/score/heap.h
+++ b/cpukit/score/include/rtems/score/heap.h
@@ -734,6 +734,7 @@ Heap_Block *_Heap_Block_allocate(
   #define _Heap_Protection_block_initialize( heap, block ) ((void) 0)
   #define _Heap_Protection_block_check( heap, block ) ((void) 0)
   #define _Heap_Protection_block_error( heap, block ) ((void) 0)
+  #define _Heap_Protection_free_all_delayed_blocks( heap ) ((void) 0)
 #else
   static inline void _Heap_Protection_block_initialize(
     Heap_Control *heap,
@@ -758,6 +759,16 @@ Heap_Block *_Heap_Block_allocate(
   {
     (*heap->Protection.block_error)( heap, block );
   }
+
+  static inline void _Heap_Protection_free_all_delayed_blocks( Heap_Control *heap )
+  {
+    uintptr_t large = 0
+      - (uintptr_t) HEAP_BLOCK_HEADER_SIZE
+      - (uintptr_t) HEAP_ALLOC_BONUS
+      - (uintptr_t) 1;
+    void *p = _Heap_Allocate( heap, large );
+    _Heap_Free( heap, p );
+  }
 #endif
 
 /** @} */
diff --git a/cpukit/score/src/heapgreedy.c b/cpukit/score/src/heapgreedy.c
index 60696f8..23eb4cd 100644
--- a/cpukit/score/src/heapgreedy.c
+++ b/cpukit/score/src/heapgreedy.c
@@ -38,6 +38,8 @@ Heap_Block *_Heap_Greedy_allocate(
   Heap_Block *current;
   size_t i;
 
+  _Heap_Protection_free_all_delayed_blocks( heap );
+
   for (i = 0; i < block_count; ++i) {
     void *next = _Heap_Allocate( heap, block_sizes [i] );
 




More information about the vc mailing list