source: proiecte/swift/trunk/lib/hoard-371/src/basehoardmanager.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// -*- C++ -*-
2
3#ifndef _BASEHOARDMANAGER_H_
4#define _BASEHOARDMANAGER_H_
5
6/**
7 * @class BaseHoardManager
8 * @brief The top of the hoard manager hierarchy.
9 *
10 */
11
12#include "sassert.h"
13
14template <class SuperblockType_>
15class BaseHoardManager {
16public:
17
18  BaseHoardManager (void)
19    : _magic (0xedded00d)
20  {}
21
22  virtual ~BaseHoardManager (void)
23  {}
24
25  inline int isValid (void) const {
26    return (_magic == 0xedded00d);
27  }
28
29  // Export the superblock type.
30  typedef SuperblockType_ SuperblockType;
31
32  /// Free an object.
33  inline virtual void free (void *) {}
34
35  /// Lock this memory manager.
36  inline virtual void lock (void) {}
37
38  /// Unlock this memory manager.
39  inline virtual void unlock (void) {};
40
41  /// Return the size of an object.
42  static inline size_t getSize (void * ptr) {
43    SuperblockType * s = getSuperblock (ptr);
44    assert (s->isValidSuperblock());
45    return s->getSize (ptr);
46  }
47
48  /// @brief Find the superblock corresponding to a pointer via bitmasking.
49  /// @note  All superblocks <em>must</em> be naturally aligned, and powers of two.
50
51  static inline SuperblockType * getSuperblock (void * ptr) {
52    return SuperblockType::getSuperblock (ptr);
53  }
54
55private:
56
57  enum { SuperblockSize = sizeof(SuperblockType) };
58
59  HL::sassert<((SuperblockSize & (SuperblockSize - 1)) == 0)> EnsureSuperblockSizeIsPowerOfTwo;
60
61  const unsigned long _magic;
62
63};
64
65#endif
Note: See TracBrowser for help on using the repository browser.