00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #ifndef _HOARD_H_
00028 #define _HOARD_H_
00029
00030 #include "hldefines.h"
00031
00032
00033
00034 #define SUPERBLOCK_SIZE 65536
00035
00036
00037 #define EMPTINESS_CLASSES 8
00038
00039
00040
00041
00042 #include "check.h"
00043 #include "fixedrequestheap.h"
00044 #include "hoardmanager.h"
00045 #include "addheaderheap.h"
00046 #include "threadpoolheap.h"
00047 #include "redirectfree.h"
00048 #include "ignoreinvalidfree.h"
00049 #include "conformantheap.h"
00050 #include "hoardsuperblock.h"
00051 #include "lockmallocheap.h"
00052 #include "alignedsuperblockheap.h"
00053 #include "alignedmmap.h"
00054 #include "globalheap.h"
00055
00056
00057
00058 #include "ansiwrapper.h"
00059 #include "debugheap.h"
00060 #include "lockedheap.h"
00061 #include "winlock.h"
00062 #include "bins4k.h"
00063 #include "bins8k.h"
00064 #include "bins16k.h"
00065 #include "bins64k.h"
00066 #include "oneheap.h"
00067 #include "freelistheap.h"
00068 #include "threadheap.h"
00069 #include "hybridheap.h"
00070 #include "posixlock.h"
00071 #include "spinlock.h"
00072
00073
00074
00075
00076
00077
00078 #if defined(_WIN32)
00079 typedef HL::WinLockType TheLockType;
00080 #elif defined(__APPLE__) || defined(__SVR4)
00081
00082
00083
00084
00085 typedef HL::SpinLockType TheLockType;
00086 #else
00087 typedef HL::SpinLockType TheLockType;
00088 #endif
00089
00090 namespace Hoard {
00091
00092
00093
00094
00095
00096 typedef GlobalHeap<SUPERBLOCK_SIZE, EMPTINESS_CLASSES, TheLockType>
00097 TheGlobalHeap;
00098
00099
00100
00101
00102
00103
00104
00105 class hoardThresholdFunctionClass {
00106 public:
00107 inline static bool function (int u, int a, size_t objSize) {
00108
00109
00110
00111
00112
00113
00114 bool r = ((EMPTINESS_CLASSES * u) < ((EMPTINESS_CLASSES-1) * a)) && ((u < a - (2 * SUPERBLOCK_SIZE) / (int) objSize));
00115 return r;
00116 }
00117 };
00118
00119
00120 class SmallHeap;
00121
00122 typedef HoardSuperblock<TheLockType, SUPERBLOCK_SIZE, SmallHeap> SmallSuperblockType;
00123
00124
00125
00126
00127 class SmallHeap :
00128 public ConformantHeap<
00129 HoardManager<AlignedSuperblockHeap<TheLockType, SUPERBLOCK_SIZE>,
00130 TheGlobalHeap,
00131 SmallSuperblockType,
00132 EMPTINESS_CLASSES,
00133 TheLockType,
00134 hoardThresholdFunctionClass,
00135 SmallHeap> > {};
00136
00137 class BigHeap;
00138
00139 typedef HoardSuperblock<TheLockType, SUPERBLOCK_SIZE, BigHeap> BigSuperblockType;
00140
00141
00142 class BigHeap :
00143 public ConformantHeap<HL::LockedHeap<TheLockType,
00144 AddHeaderHeap<BigSuperblockType,
00145 SUPERBLOCK_SIZE,
00146 AlignedMmap<SUPERBLOCK_SIZE, TheLockType> > > >
00147 {};
00148
00149
00150 enum { BigObjectSize =
00151 HL::bins<SmallSuperblockType::Header, SUPERBLOCK_SIZE>::BIG_OBJECT };
00152
00153
00154
00155
00156 class PerThreadHoardHeap :
00157 public RedirectFree<LockMallocHeap<SmallHeap>,
00158 SmallSuperblockType> {};
00159
00160 template <int N, int NH>
00161 class HoardHeap :
00162 public HL::ANSIWrapper<
00163 IgnoreInvalidFree<
00164 HL::HybridHeap<Hoard::BigObjectSize,
00165 ThreadPoolHeap<N, NH, Hoard::PerThreadHoardHeap>,
00166 Hoard::BigHeap> > >
00167 {
00168 public:
00169
00170 enum { BIG_OBJECT = Hoard::BigObjectSize };
00171
00172 HL::sassert<sizeof(Hoard::BigSuperblockType::Header)
00173 == sizeof(Hoard::SmallSuperblockType::Header)> ensureSameSizeHeaders;
00174
00175 };
00176
00177 }
00178
00179
00180 #endif