source: rtems/cpukit/score/src/heapgetinfo.c @ b041968

4.104.114.84.95
Last change on this file since b041968 was b041968, checked in by Joel Sherrill <joel.sherrill@…>, on Oct 31, 2002 at 8:09:49 PM

2002-10-31 Joel Sherrill <joel@…>

  • src/heapgetinfo.c: Fixed comment.
  • src/mpci.c: Removed warning.
  • Property mode set to 100644
File size: 2.3 KB
Line 
1/*
2 *  Heap Handler
3 *
4 *  COPYRIGHT (c) 1989-2000.
5 *  On-Line Applications Research Corporation (OAR).
6 *
7 *  The license and distribution terms for this file may be
8 *  found in the file LICENSE in this distribution or at
9 *  http://www.OARcorp.com/rtems/license.html.
10 *
11 */
12
13
14#include <rtems/system.h>
15#include <rtems/score/sysstate.h>
16#include <rtems/score/heap.h>
17
18/*PAGE
19 *
20 *  _Heap_Get_information
21 *
22 *  This kernel routine walks the heap and tots up the free and allocated
23 *  sizes.  Derived from _Heap_Walk.
24 *
25 *  Input parameters:
26 *    the_heap  - pointer to heap header
27 *    the_info  - pointer for information to be returned
28 *
29 *  Output parameters:
30 *    *the_info  - contains information about heap
31 *    return 0=success, otherwise heap is corrupt.
32 */
33
34
35Heap_Get_information_status _Heap_Get_information(
36  Heap_Control            *the_heap,
37  Heap_Information_block  *the_info
38)
39{
40  Heap_Block *the_block  = 0;  /* avoid warnings */
41  Heap_Block *next_block = 0;  /* avoid warnings */
42  int         notdone = 1;
43
44
45  the_info->free_blocks = 0;
46  the_info->free_size   = 0;
47  the_info->used_blocks = 0;
48  the_info->used_size   = 0;
49
50  /*
51   * We don't want to allow walking the heap until we have
52   * transferred control to the user task so we watch the
53   * system state.
54   */
55
56  if ( !_System_state_Is_up( _System_state_Get() ) )
57    return HEAP_GET_INFORMATION_SYSTEM_STATE_ERROR;
58
59  the_block = the_heap->start;
60
61  /*
62   * Handle the 1st block
63   */
64
65  if ( the_block->back_flag != HEAP_DUMMY_FLAG ) {
66    return HEAP_GET_INFORMATION_BLOCK_ERROR;
67  }
68
69  while (notdone) {
70     
71      /*
72       * Accumulate size
73       */
74
75      if ( _Heap_Is_block_free(the_block) ) {
76        the_info->free_blocks++;
77        the_info->free_size += _Heap_Block_size(the_block);
78      } else {
79        the_info->used_blocks++;
80        the_info->used_size += _Heap_Block_size(the_block);
81      }
82   
83      /*
84       * Handle the last block
85       */
86
87      if ( the_block->front_flag != HEAP_DUMMY_FLAG ) {
88        next_block = _Heap_Next_block(the_block);
89        if ( the_block->front_flag != next_block->back_flag ) {
90          return HEAP_GET_INFORMATION_BLOCK_ERROR;
91        }
92      }
93
94      if ( the_block->front_flag == HEAP_DUMMY_FLAG )
95        notdone = 0;
96      else
97        the_block = next_block;
98  }  /* while(notdone) */
99
100  return HEAP_GET_INFORMATION_SUCCESSFUL;
101}
Note: See TracBrowser for help on using the repository browser.