Index: cpukit/ChangeLog
===================================================================
--- cpukit/ChangeLog	(revision 7e0ef0f7b3b3cc17de3b44fcc2707a9eb9ffbef4)
+++ cpukit/ChangeLog	(revision a89ae540c1d287d275943fd06692a44e9dbc8331)
@@ -1,2 +1,12 @@
+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().
+
 2011-12-06	Ralf CorsÃ©pius <ralf.corsepius@rtems.org>
 
Index: cpukit/score/Makefile.am
===================================================================
--- cpukit/score/Makefile.am	(revision 7e0ef0f7b3b3cc17de3b44fcc2707a9eb9ffbef4)
+++ cpukit/score/Makefile.am	(revision a89ae540c1d287d275943fd06692a44e9dbc8331)
@@ -182,5 +182,5 @@
 libscore_a_SOURCES += src/heap.c src/heapallocate.c src/heapextend.c \
     src/heapfree.c src/heapsizeofuserarea.c src/heapwalk.c src/heapgetinfo.c \
-    src/heapgetfreeinfo.c src/heapresizeblock.c
+    src/heapgetfreeinfo.c src/heapresizeblock.c src/heapiterate.c
 
 ## OBJECT_C_FILES
@@ -260,5 +260,5 @@
     src/pheapextend.c src/pheapfree.c src/pheapgetsize.c \
     src/pheapgetblocksize.c src/pheapgetfreeinfo.c src/pheapgetinfo.c \
-    src/pheapinit.c src/pheapresizeblock.c src/pheapwalk.c
+    src/pheapinit.c src/pheapresizeblock.c src/pheapwalk.c src/pheapiterate.c
 
 ## RBTREE_C_FILES
Index: cpukit/score/include/rtems/score/heap.h
===================================================================
--- cpukit/score/include/rtems/score/heap.h	(revision 7e0ef0f7b3b3cc17de3b44fcc2707a9eb9ffbef4)
+++ cpukit/score/include/rtems/score/heap.h	(revision a89ae540c1d287d275943fd06692a44e9dbc8331)
@@ -523,4 +523,31 @@
 
 /**
+ * @brief Heap block visitor.
+ *
+ * @see _Heap_Iterate().
+ *
+ * @retval true Stop the iteration.
+ * @retval false Continue the iteration.
+ */
+typedef bool (*Heap_Block_visitor)(
+  const Heap_Block *block,
+  uintptr_t block_size,
+  bool block_is_used,
+  void *visitor_arg
+);
+
+/**
+ * @brief Iterates over all blocks of the heap.
+ *
+ * For each block the @a visitor with the argument @a visitor_arg will be
+ * called.
+ */
+void _Heap_Iterate(
+  Heap_Control *heap,
+  Heap_Block_visitor visitor,
+  void *visitor_arg
+);
+
+/**
  * @brief Returns information about used and free blocks for the heap @a heap
  * in @a info.
Index: cpukit/score/include/rtems/score/protectedheap.h
===================================================================
--- cpukit/score/include/rtems/score/protectedheap.h	(revision 7e0ef0f7b3b3cc17de3b44fcc2707a9eb9ffbef4)
+++ cpukit/score/include/rtems/score/protectedheap.h	(revision a89ae540c1d287d275943fd06692a44e9dbc8331)
@@ -132,4 +132,13 @@
 
 /**
+ * @brief See _Heap_Iterate().
+ */
+void _Protected_heap_Iterate(
+  Heap_Control *heap,
+  Heap_Block_visitor visitor,
+  void *visitor_arg
+);
+
+/**
  * @brief See _Heap_Get_information().
  *
Index: cpukit/score/src/heapgetinfo.c
===================================================================
--- cpukit/score/src/heapgetinfo.c	(revision 7e0ef0f7b3b3cc17de3b44fcc2707a9eb9ffbef4)
+++ cpukit/score/src/heapgetinfo.c	(revision a89ae540c1d287d275943fd06692a44e9dbc8331)
@@ -24,7 +24,24 @@
 #include <string.h>
 
-#include <rtems/system.h>
-#include <rtems/score/sysstate.h>
 #include <rtems/score/heap.h>
+
+static bool _Heap_Get_information_visitor(
+  const Heap_Block *block __attribute__((unused)),
+  uintptr_t block_size,
+  bool block_is_used,
+  void *visitor_arg
+)
+{
+  Heap_Information_block *info_block = visitor_arg;
+  Heap_Information *info = block_is_used ?
+    &info_block->Used : &info_block->Free;
+
+  ++info->number;
+  info->total += block_size;
+  if ( info->largest < block_size )
+    info->largest = block_size;
+
+  return false;
+}
 
 void _Heap_Get_information(
@@ -33,25 +50,5 @@
 )
 {
-  Heap_Block *the_block = the_heap->first_block;
-  Heap_Block *const end = the_heap->last_block;
-
-  memset(the_info, 0, sizeof(*the_info));
-
-  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;
-
-    the_block = next_block;
-  }
+  memset( the_info, 0, sizeof(*the_info) );
+  _Heap_Iterate( the_heap, _Heap_Get_information_visitor, the_info );
 }
Index: cpukit/score/src/heapiterate.c
===================================================================
--- cpukit/score/src/heapiterate.c	(revision a89ae540c1d287d275943fd06692a44e9dbc8331)
+++ cpukit/score/src/heapiterate.c	(revision a89ae540c1d287d275943fd06692a44e9dbc8331)
@@ -0,0 +1,50 @@
+/**
+ * @file
+ *
+ * @ingroup ScoreHeap
+ *
+ * @brief _Heap_Iterate() implementation.
+ */
+
+/*
+ * Copyright (c) 2011 embedded brains GmbH.  All rights reserved.
+ *
+ *  embedded brains GmbH
+ *  Obere Lagerstr. 30
+ *  82178 Puchheim
+ *  Germany
+ *  <rtems@embedded-brains.de>
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+  #include "config.h"
+#endif
+
+#include <rtems/score/heap.h>
+
+void _Heap_Iterate(
+  Heap_Control *heap,
+  Heap_Block_visitor visitor,
+  void *visitor_arg
+)
+{
+  Heap_Block *current = heap->first_block;
+  Heap_Block *end = heap->last_block;
+  bool stop = false;
+
+  while ( !stop && current != end ) {
+    uintptr_t size = _Heap_Block_size( current );
+    Heap_Block *next = _Heap_Block_at( current, size );
+    bool used = _Heap_Is_prev_used( next );
+
+    stop = (*visitor)( current, size, used, visitor_arg );
+
+    current = next;
+  }
+}
Index: cpukit/score/src/pheapiterate.c
===================================================================
--- cpukit/score/src/pheapiterate.c	(revision a89ae540c1d287d275943fd06692a44e9dbc8331)
+++ cpukit/score/src/pheapiterate.c	(revision a89ae540c1d287d275943fd06692a44e9dbc8331)
@@ -0,0 +1,40 @@
+/**
+ * @file
+ *
+ * @ingroup ScoreProtHeap
+ *
+ * @brief _Heap_Iterate() implementation.
+ */
+
+/*
+ * Copyright (c) 2011 embedded brains GmbH.  All rights reserved.
+ *
+ *  embedded brains GmbH
+ *  Obere Lagerstr. 30
+ *  82178 Puchheim
+ *  Germany
+ *  <rtems@embedded-brains.de>
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+  #include "config.h"
+#endif
+
+#include <rtems/score/protectedheap.h>
+
+void _Protected_heap_Iterate(
+  Heap_Control *heap,
+  Heap_Block_visitor visitor,
+  void *visitor_arg
+)
+{
+  _RTEMS_Lock_allocator();
+  _Heap_Iterate( heap, visitor, visitor_arg );
+  _RTEMS_Unlock_allocator();
+}
