source: proiecte/swift/trunk/lib/hoard-371/src/globalheap.h @ 176

Last change on this file since 176 was 176, checked in by (none), 14 years ago
  • imported repo from "guagal"
File size: 1.4 KB
Line 
1#ifndef _GLOBALHEAP_H_
2#define _GLOBALHEAP_H_
3
4#include "hoardsuperblock.h"
5#include "processheap.h"
6
7namespace Hoard {
8
9template <size_t SuperblockSize,
10          int EmptinessClasses,
11          class LockType>
12class GlobalHeap {
13 
14  class bogusThresholdFunctionClass {
15  public:
16    static inline bool function (int, int, size_t) {
17      // We *never* cross the threshold for a process heap.
18      return false;
19    }
20  };
21 
22public:
23
24  GlobalHeap (void) 
25    : theHeap (getHeap())
26    {
27    }
28 
29  typedef ProcessHeap<SuperblockSize, EmptinessClasses, LockType, bogusThresholdFunctionClass> SuperHeap;
30  typedef HoardSuperblock<LockType, SuperblockSize, GlobalHeap> SuperblockType;
31
32  void put (void * s, size_t sz) {
33    assert (s);
34    assert (((SuperblockType *) s)->isValidSuperblock());
35    theHeap->put ((typename SuperHeap::SuperblockType *) s,
36                  sz);
37  }
38
39  SuperblockType * get (size_t sz, void * dest) {
40    SuperblockType * s = 
41      reinterpret_cast<SuperblockType *>
42      (theHeap->get (sz, reinterpret_cast<SuperHeap *>(dest)));
43    if (s) {
44      assert (s->isValidSuperblock());
45    }
46    return s;
47  }
48
49private:
50
51  SuperHeap * theHeap;
52
53  inline static SuperHeap * getHeap (void) {
54    static double theHeapBuf[sizeof(SuperHeap) / sizeof(double) + 1];
55    static SuperHeap * theHeap = new (&theHeapBuf[0]) SuperHeap;
56    return theHeap;
57  }
58
59  // Prevent copying.
60  GlobalHeap (const GlobalHeap&);
61  GlobalHeap& operator=(const GlobalHeap&);
62
63};
64
65};
66
67#endif
Note: See TracBrowser for help on using the repository browser.