summaryrefslogtreecommitdiffstats
path: root/cpukit/score/src/heapgetinfo.c
diff options
context:
space:
mode:
authorSebastian Huber <sebastian.huber@embedded-brains.de>2011-12-06 14:23:26 +0000
committerSebastian Huber <sebastian.huber@embedded-brains.de>2011-12-06 14:23:26 +0000
commita89ae540c1d287d275943fd06692a44e9dbc8331 (patch)
tree74711aaa01d5604e4895588556f6f99c2ee2f6d2 /cpukit/score/src/heapgetinfo.c
parent2011-12-06 Sebastian Huber <sebastian.huber@embedded-brains.de> (diff)
downloadrtems-a89ae540c1d287d275943fd06692a44e9dbc8331.tar.bz2
2011-12-06 Sebastian Huber <sebastian.huber@embedded-brains.de>
* score/src/heapiterate.c, score/src/pheapiterate.c: New files. * score/Makefile.am: Reflect changes above. * score/include/rtems/score/heap.h: Declare _Heap_Iterate() and define Heap_Block_visitor. * score/include/rtems/score/protectedheap.h: Declare _Protected_heap_Iterate(). * score/src/heapgetinfo.c: Use _Heap_Iterate().
Diffstat (limited to 'cpukit/score/src/heapgetinfo.c')
-rw-r--r--cpukit/score/src/heapgetinfo.c45
1 files changed, 21 insertions, 24 deletions
diff --git a/cpukit/score/src/heapgetinfo.c b/cpukit/score/src/heapgetinfo.c
index bcb5a7f68d..872edc76ba 100644
--- a/cpukit/score/src/heapgetinfo.c
+++ b/cpukit/score/src/heapgetinfo.c
@@ -23,35 +23,32 @@
#include <string.h>
-#include <rtems/system.h>
-#include <rtems/score/sysstate.h>
#include <rtems/score/heap.h>
-void _Heap_Get_information(
- Heap_Control *the_heap,
- Heap_Information_block *the_info
+static bool _Heap_Get_information_visitor(
+ const Heap_Block *block __attribute__((unused)),
+ uintptr_t block_size,
+ bool block_is_used,
+ void *visitor_arg
)
{
- Heap_Block *the_block = the_heap->first_block;
- Heap_Block *const end = the_heap->last_block;
+ Heap_Information_block *info_block = visitor_arg;
+ Heap_Information *info = block_is_used ?
+ &info_block->Used : &info_block->Free;
- memset(the_info, 0, sizeof(*the_info));
+ ++info->number;
+ info->total += block_size;
+ if ( info->largest < block_size )
+ info->largest = block_size;
- while ( the_block != end ) {
- uintptr_t const the_size = _Heap_Block_size(the_block);
- Heap_Block *const next_block = _Heap_Block_at(the_block, the_size);
- Heap_Information *info;
-
- if ( _Heap_Is_prev_used(next_block) )
- info = &the_info->Used;
- else
- info = &the_info->Free;
-
- info->number++;
- info->total += the_size;
- if ( info->largest < the_size )
- info->largest = the_size;
+ return false;
+}
- the_block = next_block;
- }
+void _Heap_Get_information(
+ Heap_Control *the_heap,
+ Heap_Information_block *the_info
+)
+{
+ memset( the_info, 0, sizeof(*the_info) );
+ _Heap_Iterate( the_heap, _Heap_Get_information_visitor, the_info );
}