summaryrefslogtreecommitdiffstats
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
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().
-rw-r--r--cpukit/ChangeLog10
-rw-r--r--cpukit/score/Makefile.am4
-rw-r--r--cpukit/score/include/rtems/score/heap.h27
-rw-r--r--cpukit/score/include/rtems/score/protectedheap.h9
-rw-r--r--cpukit/score/src/heapgetinfo.c45
-rw-r--r--cpukit/score/src/heapiterate.c50
-rw-r--r--cpukit/score/src/pheapiterate.c40
7 files changed, 159 insertions, 26 deletions
diff --git a/cpukit/ChangeLog b/cpukit/ChangeLog
index 7ac483abf2..85db5f4645 100644
--- a/cpukit/ChangeLog
+++ b/cpukit/ChangeLog
@@ -1,3 +1,13 @@
+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>
* libcsupport/src/flockfile.c, libcsupport/src/ftrylockfile.c,
diff --git a/cpukit/score/Makefile.am b/cpukit/score/Makefile.am
index 24d71b722e..d5e938570e 100644
--- a/cpukit/score/Makefile.am
+++ b/cpukit/score/Makefile.am
@@ -181,7 +181,7 @@ endif
## HEAP_C_FILES
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
libscore_a_SOURCES += src/objectallocate.c src/objectclose.c \
@@ -259,7 +259,7 @@ libscore_a_SOURCES += src/schedulercbs.c \
libscore_a_SOURCES += src/pheapallocate.c \
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
libscore_a_SOURCES += src/rbtree.c \
diff --git a/cpukit/score/include/rtems/score/heap.h b/cpukit/score/include/rtems/score/heap.h
index 6eee1c745b..1996fb80ff 100644
--- a/cpukit/score/include/rtems/score/heap.h
+++ b/cpukit/score/include/rtems/score/heap.h
@@ -522,6 +522,33 @@ bool _Heap_Walk(
);
/**
+ * @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.
*/
diff --git a/cpukit/score/include/rtems/score/protectedheap.h b/cpukit/score/include/rtems/score/protectedheap.h
index 01c736d6ae..84f7d60097 100644
--- a/cpukit/score/include/rtems/score/protectedheap.h
+++ b/cpukit/score/include/rtems/score/protectedheap.h
@@ -131,6 +131,15 @@ bool _Protected_heap_Free( Heap_Control *heap, void *addr );
bool _Protected_heap_Walk( Heap_Control *heap, int source, bool dump );
/**
+ * @brief See _Heap_Iterate().
+ */
+void _Protected_heap_Iterate(
+ Heap_Control *heap,
+ Heap_Block_visitor visitor,
+ void *visitor_arg
+);
+
+/**
* @brief See _Heap_Get_information().
*
* Returns @a true in case of success, and @a false otherwise.
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 );
}
diff --git a/cpukit/score/src/heapiterate.c b/cpukit/score/src/heapiterate.c
new file mode 100644
index 0000000000..b9100b9149
--- /dev/null
+++ b/cpukit/score/src/heapiterate.c
@@ -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;
+ }
+}
diff --git a/cpukit/score/src/pheapiterate.c b/cpukit/score/src/pheapiterate.c
new file mode 100644
index 0000000000..ec98f75ad2
--- /dev/null
+++ b/cpukit/score/src/pheapiterate.c
@@ -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();
+}