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

Last change on this file since a6eef8b was a6eef8b, checked in by Joel Sherrill <joel.sherrill@…>, on 09/04/03 at 18:52:48

2003-09-04 Joel Sherrill <joel@…>

  • apiext.c, chain.c, coremsg.c, coremsgbroadcast.c, coremsgclose.c, coremsgflush.c, coremsgflushsupp.c, coremsgflushwait.c, coremsginsert.c, coremsgseize.c, coremsgsubmit.c, coremutex.c, coremutexflush.c, coremutexseize.c, coremutexsurrender.c, coresem.c, coresemflush.c, coresemseize.c, coresemsurrender.c, coretod.c, coretodset.c, coretodtickle.c, coretodtoseconds.c, coretodvalidate.c, heap.c, heapallocate.c, heapextend.c, heapfree.c, heapgetinfo.c, heapsizeofuserarea.c, heapwalk.c, interr.c, isr.c, mpci.c, object.c, objectallocate.c, objectallocatebyindex.c, objectclearname.c, objectcomparenameraw.c, objectcomparenamestring.c, objectcopynameraw.c, objectcopynamestring.c, objectextendinformation.c, objectfree.c, objectget.c, objectgetbyindex.c, objectgetisr.c, objectgetnext.c, objectgetnoprotection.c, objectinitializeinformation.c, objectmp.c, objectnametoid.c, objectshrinkinformation.c, thread.c, threadchangepriority.c, threadclearstate.c, threadclose.c, threadcreateidle.c, threaddelayended.c, threaddispatch.c, threadevaluatemode.c, threadget.c, threadhandler.c, threadidlebody.c, threadinitialize.c, threadloadenv.c, threadmp.c, threadq.c, threadqdequeue.c, threadqdequeuefifo.c, threadqdequeuepriority.c, threadqenqueue.c, threadqenqueuefifo.c, threadqenqueuepriority.c, threadqextract.c, threadqextractfifo.c, threadqextractpriority.c, threadqextractwithproxy.c, threadqfirst.c, threadqfirstfifo.c, threadqfirstpriority.c, threadqflush.c, threadqtimeout.c, threadready.c, threadreset.c, threadresettimeslice.c, threadrestart.c, threadresume.c, threadrotatequeue.c, threadsetpriority.c, threadsetstate.c, threadsettransient.c, threadstackallocate.c, threadstackfree.c, threadstart.c, threadstartmultitasking.c, threadsuspend.c, threadtickletimeslice.c, threadyieldprocessor.c, userext.c, watchdog.c, watchdogadjust.c, watchdoginsert.c, watchdogremove.c, watchdogtickle.c, wkspace.c: URL for license changed.
  • 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.rtems.com/license/LICENSE.
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.