1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
// -*- C++ -*-
/*
The Hoard Multiprocessor Memory Allocator
www.hoard.org
Author: Emery Berger, http://www.emeryberger.com
Copyright (c) 1998-2020 Emery Berger
See the LICENSE file at the top-level directory of this
distribution and at http://github.com/emeryberger/Hoard.
*/
#ifndef HOARD_BASEHOARDMANAGER_H
#define HOARD_BASEHOARDMANAGER_H
/**
* @class BaseHoardManager
* @brief The top of the hoard manager hierarchy.
*
*/
#include "heaplayers.h"
namespace Hoard {
template <class SuperblockType_>
class BaseHoardManager {
public:
BaseHoardManager (void)
: _magic (0xedded00d)
{
static_assert((SuperblockSize & (SuperblockSize - 1)) == 0,
"Size of superblock must be a power of two.");
}
inline int isValid (void) const {
return (_magic == 0xedded00d);
}
// Export the superblock type.
typedef SuperblockType_ SuperblockType;
/// Free an object.
inline virtual void free (void *) {}
/// Lock this memory manager.
inline virtual void lock (void) {}
/// Unlock this memory manager.
inline virtual void unlock (void) {};
/// Return the size of an object.
static inline size_t getSize (void * ptr) {
SuperblockType * s = getSuperblock (ptr);
assert (s->isValidSuperblock());
return s->getSize (ptr);
}
/// @brief Find the superblock corresponding to a pointer via bitmasking.
/// @note All superblocks <em>must</em> be naturally aligned, and powers of two.
static inline SuperblockType * getSuperblock (void * ptr) {
return SuperblockType::getSuperblock (ptr);
}
private:
enum { SuperblockSize = sizeof(SuperblockType) };
const unsigned long _magic;
};
}
#endif