1*8728f479SAugustin Cavalier ///-*-C++-*-//////////////////////////////////////////////////////////////////
2*8728f479SAugustin Cavalier //
3*8728f479SAugustin Cavalier // Hoard: A Fast, Scalable, and Memory-Efficient Allocator
4*8728f479SAugustin Cavalier // for Shared-Memory Multiprocessors
5*8728f479SAugustin Cavalier // Contact author: Emery Berger, http://www.cs.utexas.edu/users/emery
6*8728f479SAugustin Cavalier //
7*8728f479SAugustin Cavalier // Copyright (c) 1998-2000, The University of Texas at Austin.
8*8728f479SAugustin Cavalier //
9*8728f479SAugustin Cavalier // This library is free software; you can redistribute it and/or modify
10*8728f479SAugustin Cavalier // it under the terms of the GNU Library General Public License as
11*8728f479SAugustin Cavalier // published by the Free Software Foundation, http://www.fsf.org.
12*8728f479SAugustin Cavalier //
13*8728f479SAugustin Cavalier // This library is distributed in the hope that it will be useful, but
14*8728f479SAugustin Cavalier // WITHOUT ANY WARRANTY; without even the implied warranty of
15*8728f479SAugustin Cavalier // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16*8728f479SAugustin Cavalier // Library General Public License for more details.
17*8728f479SAugustin Cavalier //
18*8728f479SAugustin Cavalier //////////////////////////////////////////////////////////////////////////////
19*8728f479SAugustin Cavalier #ifndef _HEAPSTATS_H_
20*8728f479SAugustin Cavalier #define _HEAPSTATS_H_
21*8728f479SAugustin Cavalier
22*8728f479SAugustin Cavalier #include "config.h"
23*8728f479SAugustin Cavalier
24*8728f479SAugustin Cavalier //#include <stdio.h>
25*8728f479SAugustin Cavalier //#include <assert.h>
26*8728f479SAugustin Cavalier
27*8728f479SAugustin Cavalier
28*8728f479SAugustin Cavalier class heapStats {
29*8728f479SAugustin Cavalier public:
heapStats(void)30*8728f479SAugustin Cavalier heapStats(void)
31*8728f479SAugustin Cavalier : U(0), A(0)
32*8728f479SAugustin Cavalier #if HEAP_STATS
33*8728f479SAugustin Cavalier , Umax(0), Amax(0)
34*8728f479SAugustin Cavalier #endif
35*8728f479SAugustin Cavalier {
36*8728f479SAugustin Cavalier }
37*8728f479SAugustin Cavalier
38*8728f479SAugustin Cavalier inline const heapStats & operator=(const heapStats & p);
39*8728f479SAugustin Cavalier
40*8728f479SAugustin Cavalier inline void incStats(int updateU, int updateA);
41*8728f479SAugustin Cavalier inline void incUStats(void);
42*8728f479SAugustin Cavalier
43*8728f479SAugustin Cavalier inline void decStats(int updateU, int updateA);
44*8728f479SAugustin Cavalier inline void decUStats(void);
45*8728f479SAugustin Cavalier inline void decUStats(int &Uout, int &Aout);
46*8728f479SAugustin Cavalier
47*8728f479SAugustin Cavalier inline void getStats(int &Uout, int &Aout);
48*8728f479SAugustin Cavalier
49*8728f479SAugustin Cavalier #if HEAP_STATS
50*8728f479SAugustin Cavalier inline int getUmax(void);
51*8728f479SAugustin Cavalier inline int getAmax(void);
52*8728f479SAugustin Cavalier #endif
53*8728f479SAugustin Cavalier
54*8728f479SAugustin Cavalier private:
55*8728f479SAugustin Cavalier // U and A *must* be the first items in this class --
56*8728f479SAugustin Cavalier // we will depend on this to atomically update them.
57*8728f479SAugustin Cavalier
58*8728f479SAugustin Cavalier int U; // Memory in use.
59*8728f479SAugustin Cavalier int A; // Memory allocated.
60*8728f479SAugustin Cavalier
61*8728f479SAugustin Cavalier #if HEAP_STATS
62*8728f479SAugustin Cavalier int Umax;
63*8728f479SAugustin Cavalier int Amax;
64*8728f479SAugustin Cavalier #endif
65*8728f479SAugustin Cavalier };
66*8728f479SAugustin Cavalier
67*8728f479SAugustin Cavalier
68*8728f479SAugustin Cavalier inline void
incStats(int updateU,int updateA)69*8728f479SAugustin Cavalier heapStats::incStats(int updateU, int updateA)
70*8728f479SAugustin Cavalier {
71*8728f479SAugustin Cavalier assert(updateU >= 0);
72*8728f479SAugustin Cavalier assert(updateA >= 0);
73*8728f479SAugustin Cavalier assert(U <= A);
74*8728f479SAugustin Cavalier assert(U >= 0);
75*8728f479SAugustin Cavalier assert(A >= 0);
76*8728f479SAugustin Cavalier U += updateU;
77*8728f479SAugustin Cavalier A += updateA;
78*8728f479SAugustin Cavalier
79*8728f479SAugustin Cavalier #if HEAP_STATS
80*8728f479SAugustin Cavalier Amax = MAX(Amax, A);
81*8728f479SAugustin Cavalier Umax = MAX(Umax, U);
82*8728f479SAugustin Cavalier #endif
83*8728f479SAugustin Cavalier
84*8728f479SAugustin Cavalier assert(U <= A);
85*8728f479SAugustin Cavalier assert(U >= 0);
86*8728f479SAugustin Cavalier assert(A >= 0);
87*8728f479SAugustin Cavalier }
88*8728f479SAugustin Cavalier
89*8728f479SAugustin Cavalier
90*8728f479SAugustin Cavalier inline void
incUStats(void)91*8728f479SAugustin Cavalier heapStats::incUStats(void)
92*8728f479SAugustin Cavalier {
93*8728f479SAugustin Cavalier assert(U < A);
94*8728f479SAugustin Cavalier assert(U >= 0);
95*8728f479SAugustin Cavalier assert(A >= 0);
96*8728f479SAugustin Cavalier U++;
97*8728f479SAugustin Cavalier
98*8728f479SAugustin Cavalier #if HEAP_STATS
99*8728f479SAugustin Cavalier Umax = MAX(Umax, U);
100*8728f479SAugustin Cavalier #endif
101*8728f479SAugustin Cavalier
102*8728f479SAugustin Cavalier assert(U >= 0);
103*8728f479SAugustin Cavalier assert(A >= 0);
104*8728f479SAugustin Cavalier }
105*8728f479SAugustin Cavalier
106*8728f479SAugustin Cavalier
107*8728f479SAugustin Cavalier inline void
decStats(int updateU,int updateA)108*8728f479SAugustin Cavalier heapStats::decStats(int updateU, int updateA)
109*8728f479SAugustin Cavalier {
110*8728f479SAugustin Cavalier assert(updateU >= 0);
111*8728f479SAugustin Cavalier assert(updateA >= 0);
112*8728f479SAugustin Cavalier assert(U <= A);
113*8728f479SAugustin Cavalier assert(U >= updateU);
114*8728f479SAugustin Cavalier assert(A >= updateA);
115*8728f479SAugustin Cavalier U -= updateU;
116*8728f479SAugustin Cavalier A -= updateA;
117*8728f479SAugustin Cavalier assert(U <= A);
118*8728f479SAugustin Cavalier assert(U >= 0);
119*8728f479SAugustin Cavalier assert(A >= 0);
120*8728f479SAugustin Cavalier }
121*8728f479SAugustin Cavalier
122*8728f479SAugustin Cavalier
123*8728f479SAugustin Cavalier inline void
decUStats(int & Uout,int & Aout)124*8728f479SAugustin Cavalier heapStats::decUStats(int &Uout, int &Aout)
125*8728f479SAugustin Cavalier {
126*8728f479SAugustin Cavalier assert(U <= A);
127*8728f479SAugustin Cavalier assert(U > 0);
128*8728f479SAugustin Cavalier assert(A >= 0);
129*8728f479SAugustin Cavalier U--;
130*8728f479SAugustin Cavalier Uout = U;
131*8728f479SAugustin Cavalier Aout = A;
132*8728f479SAugustin Cavalier assert(U >= 0);
133*8728f479SAugustin Cavalier assert(A >= 0);
134*8728f479SAugustin Cavalier }
135*8728f479SAugustin Cavalier
136*8728f479SAugustin Cavalier
137*8728f479SAugustin Cavalier inline void
decUStats(void)138*8728f479SAugustin Cavalier heapStats::decUStats(void)
139*8728f479SAugustin Cavalier {
140*8728f479SAugustin Cavalier assert(U <= A);
141*8728f479SAugustin Cavalier assert(U > 0);
142*8728f479SAugustin Cavalier assert(A >= 0);
143*8728f479SAugustin Cavalier U--;
144*8728f479SAugustin Cavalier }
145*8728f479SAugustin Cavalier
146*8728f479SAugustin Cavalier
147*8728f479SAugustin Cavalier inline void
getStats(int & Uout,int & Aout)148*8728f479SAugustin Cavalier heapStats::getStats(int &Uout, int &Aout)
149*8728f479SAugustin Cavalier {
150*8728f479SAugustin Cavalier assert(U >= 0);
151*8728f479SAugustin Cavalier assert(A >= 0);
152*8728f479SAugustin Cavalier Uout = U;
153*8728f479SAugustin Cavalier Aout = A;
154*8728f479SAugustin Cavalier assert(U <= A);
155*8728f479SAugustin Cavalier assert(U >= 0);
156*8728f479SAugustin Cavalier assert(A >= 0);
157*8728f479SAugustin Cavalier }
158*8728f479SAugustin Cavalier
159*8728f479SAugustin Cavalier
160*8728f479SAugustin Cavalier #if HEAP_STATS
161*8728f479SAugustin Cavalier inline int
getUmax(void)162*8728f479SAugustin Cavalier heapStats::getUmax(void)
163*8728f479SAugustin Cavalier {
164*8728f479SAugustin Cavalier return Umax;
165*8728f479SAugustin Cavalier }
166*8728f479SAugustin Cavalier
167*8728f479SAugustin Cavalier
168*8728f479SAugustin Cavalier inline int
getAmax(void)169*8728f479SAugustin Cavalier heapStats::getAmax(void)
170*8728f479SAugustin Cavalier {
171*8728f479SAugustin Cavalier return Amax;
172*8728f479SAugustin Cavalier }
173*8728f479SAugustin Cavalier #endif // HEAP_STATS
174*8728f479SAugustin Cavalier
175*8728f479SAugustin Cavalier #endif // _HEAPSTATS_H_
176