misc: remove #include <cassert> from misc.hh since not everyone needs it.
[gem5.git] / src / base / fast_alloc.cc
index 455fb8ed7d8cdd38b63f12f56a79c087cb2ed7ed..a91a99d20a53373d6aa9821c39071c3b556e5a1e 100644 (file)
  * by permission.
  */
 
-#ifndef NO_FAST_ALLOC
+#include <cassert>
+
+#include "base/fast_alloc.hh"
+
+#if !NO_FAST_ALLOC
 
 #ifdef __GNUC__
 #pragma implementation
 #endif
 
-#include <assert.h>
-#include "base/fast_alloc.hh"
-
 void *FastAlloc::freeLists[Num_Buckets];
 
-#ifdef FAST_ALLOC_STATS
+#if FAST_ALLOC_STATS
 unsigned FastAlloc::newCount[Num_Buckets];
 unsigned FastAlloc::deleteCount[Num_Buckets];
 unsigned FastAlloc::allocCount[Num_Buckets];
 #endif
 
-void *FastAlloc::moreStructs(int bucket)
+void *
+FastAlloc::moreStructs(int bucket)
 {
     assert(bucket > 0 && bucket < Num_Buckets);
 
     int sz = bucket * Alloc_Quantum;
-    const int nstructs = Num_Structs_Per_New;  // how many to allocate?
+    const int nstructs = Num_Structs_Per_New;   // how many to allocate?
     char *p = ::new char[nstructs * sz];
 
-#ifdef FAST_ALLOC_STATS
+#if FAST_ALLOC_STATS
     ++allocCount[bucket];
 #endif
 
@@ -71,14 +73,13 @@ void *FastAlloc::moreStructs(int bucket)
     return (p + sz);
 }
 
+#if FAST_ALLOC_DEBUG
 
-#ifdef FAST_ALLOC_DEBUG
-
-#include <typeinfo>
-#include <iostream>
 #include <iomanip>
+#include <iostream>
 #include <map>
 #include <string>
+#include <typeinfo>
 
 using namespace std;
 
@@ -97,7 +98,6 @@ FastAlloc::FastAlloc(FastAlloc *prev, FastAlloc *next)
     inUseNext = next;
 }
 
-
 // constructor: marks as in use, add to in-use list
 FastAlloc::FastAlloc()
 {
@@ -131,7 +131,6 @@ FastAlloc::~FastAlloc()
     inUseNext->inUsePrev = inUsePrev;
 }
 
-
 // summarize in-use list
 void
 FastAlloc::dump_summary()
@@ -148,50 +147,43 @@ FastAlloc::dump_summary()
     cout << " count  type\n"
          << " -----  ----\n";
     for (mapiter = typemap.begin(); mapiter != typemap.end(); ++mapiter)
-    {
         cout << setw(6) << mapiter->second << "  " << mapiter->first << endl;
-    }
 }
 
-
 // show oldest n items on in-use list
 void
 FastAlloc::dump_oldest(int n)
 {
     // sanity check: don't want to crash the debugger if you forget to
     // pass in a parameter
-    if (n < 0 || n > numInUse)
-    {
+    if (n < 0 || n > numInUse) {
         cout << "FastAlloc::dump_oldest: bad arg " << n
              << " (" << numInUse << " objects in use" << endl;
         return;
     }
 
-    for (FastAlloc *p = inUseHead.inUsePrev;
+    for (FastAlloc *p = inUseHead.inUseNext;
          p != &inUseHead && n > 0;
-         p = p->inUsePrev, --n)
-    {
+         p = p->inUseNext, --n)
         cout << p << " " << typeid(*p).name() << endl;
-    }
 }
 
-
 //
 // C interfaces to FastAlloc::dump_summary() and FastAlloc::dump_oldest().
 // gdb seems to have trouble with calling C++ functions directly.
 //
-extern "C" void
+void
 fast_alloc_summary()
 {
     FastAlloc::dump_summary();
 }
 
-extern "C" void
+void
 fast_alloc_oldest(int n)
 {
     FastAlloc::dump_oldest(n);
 }
 
-#endif
+#endif // FAST_ALLOC_DEBUG
 
 #endif // NO_FAST_ALLOC