vfs: check userland buffers before reading them.
[haiku.git] / src / system / libroot / posix / malloc / heapstats.h
blob387cac65a975f21d0950042143abf327e21c204b
1 ///-*-C++-*-//////////////////////////////////////////////////////////////////
2 //
3 // Hoard: A Fast, Scalable, and Memory-Efficient Allocator
4 // for Shared-Memory Multiprocessors
5 // Contact author: Emery Berger, http://www.cs.utexas.edu/users/emery
6 //
7 // Copyright (c) 1998-2000, The University of Texas at Austin.
8 //
9 // This library is free software; you can redistribute it and/or modify
10 // it under the terms of the GNU Library General Public License as
11 // published by the Free Software Foundation, http://www.fsf.org.
13 // This library is distributed in the hope that it will be useful, but
14 // WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 // Library General Public License for more details.
18 //////////////////////////////////////////////////////////////////////////////
19 #ifndef _HEAPSTATS_H_
20 #define _HEAPSTATS_H_
22 #include "config.h"
24 //#include <stdio.h>
25 //#include <assert.h>
28 class heapStats {
29 public:
30 heapStats(void)
31 : U(0), A(0)
32 #if HEAP_STATS
33 , Umax(0), Amax(0)
34 #endif
38 inline const heapStats & operator=(const heapStats & p);
40 inline void incStats(int updateU, int updateA);
41 inline void incUStats(void);
43 inline void decStats(int updateU, int updateA);
44 inline void decUStats(void);
45 inline void decUStats(int &Uout, int &Aout);
47 inline void getStats(int &Uout, int &Aout);
49 #if HEAP_STATS
50 inline int getUmax(void);
51 inline int getAmax(void);
52 #endif
54 private:
55 // U and A *must* be the first items in this class --
56 // we will depend on this to atomically update them.
58 int U; // Memory in use.
59 int A; // Memory allocated.
61 #if HEAP_STATS
62 int Umax;
63 int Amax;
64 #endif
68 inline void
69 heapStats::incStats(int updateU, int updateA)
71 assert(updateU >= 0);
72 assert(updateA >= 0);
73 assert(U <= A);
74 assert(U >= 0);
75 assert(A >= 0);
76 U += updateU;
77 A += updateA;
79 #if HEAP_STATS
80 Amax = MAX(Amax, A);
81 Umax = MAX(Umax, U);
82 #endif
84 assert(U <= A);
85 assert(U >= 0);
86 assert(A >= 0);
90 inline void
91 heapStats::incUStats(void)
93 assert(U < A);
94 assert(U >= 0);
95 assert(A >= 0);
96 U++;
98 #if HEAP_STATS
99 Umax = MAX(Umax, U);
100 #endif
102 assert(U >= 0);
103 assert(A >= 0);
107 inline void
108 heapStats::decStats(int updateU, int updateA)
110 assert(updateU >= 0);
111 assert(updateA >= 0);
112 assert(U <= A);
113 assert(U >= updateU);
114 assert(A >= updateA);
115 U -= updateU;
116 A -= updateA;
117 assert(U <= A);
118 assert(U >= 0);
119 assert(A >= 0);
123 inline void
124 heapStats::decUStats(int &Uout, int &Aout)
126 assert(U <= A);
127 assert(U > 0);
128 assert(A >= 0);
129 U--;
130 Uout = U;
131 Aout = A;
132 assert(U >= 0);
133 assert(A >= 0);
137 inline void
138 heapStats::decUStats(void)
140 assert(U <= A);
141 assert(U > 0);
142 assert(A >= 0);
143 U--;
147 inline void
148 heapStats::getStats(int &Uout, int &Aout)
150 assert(U >= 0);
151 assert(A >= 0);
152 Uout = U;
153 Aout = A;
154 assert(U <= A);
155 assert(U >= 0);
156 assert(A >= 0);
160 #if HEAP_STATS
161 inline int
162 heapStats::getUmax(void)
164 return Umax;
168 inline int
169 heapStats::getAmax(void)
171 return Amax;
173 #endif // HEAP_STATS
175 #endif // _HEAPSTATS_H_