usermode/library/malloc-original/src/heapstats.h

00001 
00002 //
00003 // Hoard: A Fast, Scalable, and Memory-Efficient Allocator
00004 //        for Shared-Memory Multiprocessors
00005 // Contact author: Emery Berger, http://www.cs.utexas.edu/users/emery
00006 //
00007 // Copyright (c) 1998-2000, The University of Texas at Austin.
00008 //
00009 // This library is free software; you can redistribute it and/or modify
00010 // it under the terms of the GNU Library General Public License as
00011 // published by the Free Software Foundation, http://www.fsf.org.
00012 //
00013 // This library is distributed in the hope that it will be useful, but
00014 // WITHOUT ANY WARRANTY; without even the implied warranty of
00015 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00016 // Library General Public License for more details.
00017 //
00019 #ifndef _HEAPSTATS_H_
00020 #define _HEAPSTATS_H_
00021 
00022 #include "config.h"
00023 
00024 #include <stdio.h>
00025 #include <assert.h>
00026 
00027 
00028 class heapStats {
00029 public:
00030 
00031   heapStats (void)
00032     : 
00033     U (0),
00034     A (0)
00035 #if HEAP_STATS
00036     ,Umax (0),
00037     Amax (0)
00038 #endif
00039   {}
00040 
00041   inline const heapStats& operator= (const heapStats& p);
00042 
00043   inline void incStats (int updateU, int updateA);
00044   inline void incUStats (void);
00045 
00046   inline void decStats (int updateU, int updateA);
00047   inline void decUStats (void);
00048   inline void decUStats (int& Uout, int& Aout);
00049 
00050   inline void getStats (int& Uout, int& Aout);
00051 
00052 
00053 #if HEAP_STATS
00054   
00055   inline int getUmax (void);
00056   inline int getAmax (void);
00057 
00058 #endif
00059 
00060 
00061 private:
00062 
00063   // U and A *must* be the first items in this class --
00064   // we will depend on this to atomically update them.
00065 
00066   int U;        // Memory in use.
00067   int A;        // Memory allocated.
00068 
00069 #if HEAP_STATS
00070   int Umax;
00071   int Amax;
00072 #endif
00073 };
00074 
00075 
00076 inline void heapStats::incStats (int updateU, int updateA) 
00077 {
00078   assert (updateU >= 0);
00079   assert (updateA >= 0);
00080   assert (U <= A);
00081   assert (U >= 0);
00082   assert (A >= 0);
00083   U += updateU;
00084   A += updateA;
00085 #if HEAP_STATS
00086   Amax = MAX (Amax, A);
00087   Umax = MAX (Umax, U);
00088 #endif
00089   assert (U <= A);
00090   assert (U >= 0);
00091   assert (A >= 0);
00092 }
00093 
00094 
00095 inline void heapStats::incUStats (void)
00096 {
00097   assert (U < A);
00098   assert (U >= 0);
00099   assert (A >= 0);
00100   U++;
00101 #if HEAP_STATS
00102   Umax = MAX (Umax, U);
00103 #endif
00104   assert (U >= 0);
00105   assert (A >= 0);
00106 }
00107 
00108 
00109 inline void heapStats::decStats (int updateU, int updateA)
00110 {
00111   assert (updateU >= 0);
00112   assert (updateA >= 0);
00113   assert (U <= A);
00114   assert (U >= updateU);
00115   assert (A >= updateA);
00116   U -= updateU;
00117   A -= updateA;
00118   assert (U <= A);
00119   assert (U >= 0);
00120   assert (A >= 0);
00121 }
00122 
00123 
00124 inline void heapStats::decUStats (int& Uout, int& Aout) 
00125 {
00126   assert (U <= A);
00127   assert (U > 0);
00128   assert (A >= 0);
00129   U--;
00130   Uout = U;
00131   Aout = A;
00132   assert (U >= 0);
00133   assert (A >= 0);
00134 }
00135 
00136 
00137 inline void heapStats::decUStats (void) 
00138 {
00139   assert (U <= A);
00140   assert (U > 0);
00141   assert (A >= 0);
00142   U--;
00143 }
00144 
00145 
00146 inline void heapStats::getStats (int& Uout, int& Aout) 
00147 {
00148   assert (U >= 0);
00149   assert (A >= 0);
00150   Uout = U;
00151   Aout = A;
00152   assert (U <= A);
00153   assert (U >= 0);
00154   assert (A >= 0);
00155 }
00156 
00157 
00158 #if HEAP_STATS
00159 inline int heapStats::getUmax (void) 
00160 {
00161   return Umax;
00162 }
00163 
00164 
00165 inline int heapStats::getAmax (void) 
00166 {
00167   return Amax;
00168 }
00169 #endif // HEAP_STATS
00170 
00171 
00172 
00173 #endif // _HEAPSTATS_H_

Generated on Sat Apr 23 11:43:35 2011 for Mnemosyne by  doxygen 1.4.7