Changeset a89ae540 in rtems


Ignore:
Timestamp:
Dec 6, 2011, 2:23:26 PM (7 years ago)
Author:
Sebastian Huber <sebastian.huber@…>
Branches:
4.11, master
Children:
64e0f6ca
Parents:
7e0ef0f7
Message:

2011-12-06 Sebastian Huber <sebastian.huber@…>

  • 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().
Location:
cpukit
Files:
2 added
5 edited

Legend:

Unmodified
Added
Removed
  • cpukit/ChangeLog

    r7e0ef0f7 ra89ae540  
     12011-12-06      Sebastian Huber <sebastian.huber@embedded-brains.de>
     2
     3        * score/src/heapiterate.c, score/src/pheapiterate.c: New files.
     4        * score/Makefile.am: Reflect changes above.
     5        * score/include/rtems/score/heap.h: Declare _Heap_Iterate() and define
     6        Heap_Block_visitor.
     7        * score/include/rtems/score/protectedheap.h: Declare
     8        _Protected_heap_Iterate().
     9        * score/src/heapgetinfo.c: Use _Heap_Iterate().
     10
    1112011-12-06      Ralf Corsépius <ralf.corsepius@rtems.org>
    212
  • cpukit/score/Makefile.am

    r7e0ef0f7 ra89ae540  
    182182libscore_a_SOURCES += src/heap.c src/heapallocate.c src/heapextend.c \
    183183    src/heapfree.c src/heapsizeofuserarea.c src/heapwalk.c src/heapgetinfo.c \
    184     src/heapgetfreeinfo.c src/heapresizeblock.c
     184    src/heapgetfreeinfo.c src/heapresizeblock.c src/heapiterate.c
    185185
    186186## OBJECT_C_FILES
     
    260260    src/pheapextend.c src/pheapfree.c src/pheapgetsize.c \
    261261    src/pheapgetblocksize.c src/pheapgetfreeinfo.c src/pheapgetinfo.c \
    262     src/pheapinit.c src/pheapresizeblock.c src/pheapwalk.c
     262    src/pheapinit.c src/pheapresizeblock.c src/pheapwalk.c src/pheapiterate.c
    263263
    264264## RBTREE_C_FILES
  • cpukit/score/include/rtems/score/heap.h

    r7e0ef0f7 ra89ae540  
    523523
    524524/**
     525 * @brief Heap block visitor.
     526 *
     527 * @see _Heap_Iterate().
     528 *
     529 * @retval true Stop the iteration.
     530 * @retval false Continue the iteration.
     531 */
     532typedef bool (*Heap_Block_visitor)(
     533  const Heap_Block *block,
     534  uintptr_t block_size,
     535  bool block_is_used,
     536  void *visitor_arg
     537);
     538
     539/**
     540 * @brief Iterates over all blocks of the heap.
     541 *
     542 * For each block the @a visitor with the argument @a visitor_arg will be
     543 * called.
     544 */
     545void _Heap_Iterate(
     546  Heap_Control *heap,
     547  Heap_Block_visitor visitor,
     548  void *visitor_arg
     549);
     550
     551/**
    525552 * @brief Returns information about used and free blocks for the heap @a heap
    526553 * in @a info.
  • cpukit/score/include/rtems/score/protectedheap.h

    r7e0ef0f7 ra89ae540  
    132132
    133133/**
     134 * @brief See _Heap_Iterate().
     135 */
     136void _Protected_heap_Iterate(
     137  Heap_Control *heap,
     138  Heap_Block_visitor visitor,
     139  void *visitor_arg
     140);
     141
     142/**
    134143 * @brief See _Heap_Get_information().
    135144 *
  • cpukit/score/src/heapgetinfo.c

    r7e0ef0f7 ra89ae540  
    2424#include <string.h>
    2525
    26 #include <rtems/system.h>
    27 #include <rtems/score/sysstate.h>
    2826#include <rtems/score/heap.h>
     27
     28static bool _Heap_Get_information_visitor(
     29  const Heap_Block *block __attribute__((unused)),
     30  uintptr_t block_size,
     31  bool block_is_used,
     32  void *visitor_arg
     33)
     34{
     35  Heap_Information_block *info_block = visitor_arg;
     36  Heap_Information *info = block_is_used ?
     37    &info_block->Used : &info_block->Free;
     38
     39  ++info->number;
     40  info->total += block_size;
     41  if ( info->largest < block_size )
     42    info->largest = block_size;
     43
     44  return false;
     45}
    2946
    3047void _Heap_Get_information(
     
    3350)
    3451{
    35   Heap_Block *the_block = the_heap->first_block;
    36   Heap_Block *const end = the_heap->last_block;
    37 
    38   memset(the_info, 0, sizeof(*the_info));
    39 
    40   while ( the_block != end ) {
    41     uintptr_t const     the_size = _Heap_Block_size(the_block);
    42     Heap_Block *const  next_block = _Heap_Block_at(the_block, the_size);
    43     Heap_Information  *info;
    44 
    45     if ( _Heap_Is_prev_used(next_block) )
    46       info = &the_info->Used;
    47     else
    48       info = &the_info->Free;
    49 
    50     info->number++;
    51     info->total += the_size;
    52     if ( info->largest < the_size )
    53       info->largest = the_size;
    54 
    55     the_block = next_block;
    56   }
     52  memset( the_info, 0, sizeof(*the_info) );
     53  _Heap_Iterate( the_heap, _Heap_Get_information_visitor, the_info );
    5754}
Note: See TracChangeset for help on using the changeset viewer.