Twilight Princess
Decompilation of The Legend of Zelda: Twilight Princess
Loading...
Searching...
No Matches
JASHeapCtrl.h
Go to the documentation of this file.
1#ifndef JASHEAPCTRL_H
2#define JASHEAPCTRL_H
3
8
9class JASDisposer;
10class JKRHeap;
11class JKRSolidHeap;
12
17class JASHeap {
18public:
19 /* 80290140 */ JASHeap(JASDisposer* param_0 = NULL);
20 /* 802901AC */ void initRootHeap(void*, u32);
21 /* 8029021C */ bool alloc(JASHeap*, u32);
22 /* 802903F4 */ bool allocTail(JASHeap*, u32);
23 /* 802904E4 */ bool free();
24 /* 80290608 */ void insertChild(JASHeap*, JASHeap*, void*, u32, bool);
25 /* 802906F0 */ JASHeap* getTailHeap();
26 /* 8029077C */ u32 getTailOffset();
27 /* 802907E0 */ u32 getCurOffset();
28 /* 80290B54 */ ~JASHeap() {}
29
30 void* getBase() { return mBase; }
31 bool isAllocated() { return mBase; }
32 u32 getSize() { return mSize; }
33
35 /* 0x1C */ OSMutex mMutex;
37 /* 0x38 */ u8* mBase;
38 /* 0x3C */ u32 mSize;
39 /* 0x40 */ JASHeap* field_0x40;
40};
41
47 /* 80290848 */ JASGenericMemPool();
48 /* 80290860 */ ~JASGenericMemPool();
49 /* 802908C8 */ void newMemPool(u32, int);
50 /* 80290948 */ void* alloc(u32);
51 /* 80290994 */ void free(void*, u32);
52
53 /* 0x00 */ void* field_0x0;
54 /* 0x04 */ u32 freeMemCount;
55 /* 0x08 */ u32 totalMemCount;
56 /* 0x0C */ u32 usedMemCount;
57
58};
59
61 template <typename A0>
70
71
73 // Should be templated on the chunk memory but couldn't initialize it inside the class itself
74 //template <typename A0>
75 struct Lock {
76 Lock(OSMutex* mutex) {
77 mMutex = mutex;
79 }
80
83 }
84
86 };
87 };
88};
89
94template <typename T>
96public:
98 void* alloc(u32 n) { return JASGenericMemPool::alloc(n); }
99 void free(void* ptr, u32 n) { JASGenericMemPool::free(ptr, n); }
100};
101
106template<u32 ChunkSize, typename T>
108 struct MemoryChunk {
114
115 bool checkArea(void* ptr) {
116 return (u8*)this + 0xc <= (u8*)ptr && (u8*)ptr < (u8*)this + (ChunkSize + 0xc);
117 }
118
120 return mNextChunk;
121 }
122
123 void* alloc(u32 size) {
124 u8* rv = mBuffer + mUsedSize;
125 mUsedSize += size;
126 mChunks++;
127 return rv;
128 }
129
130 void free() {
131 mChunks--;
132 }
133
134 bool isEmpty() {
135 return mChunks == 0;
136 }
137
141
143 return ChunkSize - mUsedSize;
144 }
145
146 void revive() {
147 mUsedSize = 0;
148 }
149
154 };
155public:
161
163 bool uVar2;
164 if (field_0x18 != NULL && field_0x18->isEmpty()) {
166 uVar2 = 1;
167 } else {
170 if (field_0x18 != NULL) {
171 uVar2 = 1;
172 } else {
174 if (field_0x18 != NULL) {
175 uVar2 = 1;
176 } else {
178 uVar2 = 0;
179 }
180 }
181 }
182 return uVar2;
183 }
184
185 void* alloc(u32 size) {
186 T::Lock lock(&mMutex);
187 if (field_0x18->getFreeSize() < size) {
188 if (ChunkSize < size) {
189 return NULL;
190 }
191 if (createNewChunk() == 0) {
192 return NULL;
193 }
194 }
195 return field_0x18->alloc(size);
196 }
197
198 void free(void* ptr) {
199 T::Lock lock(&mMutex);
202 while (chunk != NULL) {
203 if (chunk->checkArea(ptr)) {
204 chunk->free();
205 if (chunk != field_0x18 && chunk->isEmpty()) {
207 delete chunk;
209 }
210 return;
211 }
213 chunk = chunk->getNextChunk();
214 }
215 }
216
217 /* 0x00 */ OSMutex mMutex;
219};
220
221namespace JASKernel {
222 /* 802909B8 */ void setupRootHeap(JKRSolidHeap*, u32);
223 /* 80290AC0 */ JKRHeap* getSystemHeap();
225 /* 80290AD0 */ void setupAramHeap(u32, u32);
226 /* 80290B08 */ JASHeap* getAramHeap();
227
228 extern JASHeap audioAramHeap;
229 extern u32 sAramBase;
230 extern JKRHeap* sSystemHeap;
232};
233
238template <typename T>
240public:
241 static void* operator new(size_t n) {
243 return memPool->alloc(sizeof(T));
244 }
245 static void* operator new(size_t n, void* ptr) {
246 return ptr;
247 }
248 static void operator delete(void* ptr, size_t n) {
250 memPool_->free(ptr, sizeof(T));
251 }
252 static void newMemPool(int param_0) {
254 memPool_->newMemPool(param_0);
255 }
256
257private:
259 static JASMemPool<T> memPool_;
260 return &memPool_;
261 }
262};
263
268template <typename T>
286
291template <typename T>
293public:
294 static void* operator new(size_t n) {
296 return memPool_->alloc(sizeof(T));
297 }
298 static void* operator new(size_t n, void* ptr) {
299 return ptr;
300 }
301 static void operator delete(void* ptr, size_t n) {
303 memPool_->free(ptr, sizeof(T));
304 }
305
306 static void newMemPool(int n) {
307 getMemPool()->newMemPool(n);
308 }
309
310private:
315};
316
317extern JKRSolidHeap* JASDram;
318
319#endif /* JASHEAPCTRL_H */
JKRSolidHeap * JASDram
Definition JASHeapCtrl.cpp:218
asm BOOL OSRestoreInterrupts(register BOOL status)
Definition OSInterrupt.c:46
asm BOOL OSDisableInterrupts(void)
Definition OSInterrupt.c:10
void OSInitMutex(OSMutex *mutex)
Definition OSMutex.c:55
void OSUnlockMutex(OSMutex *mutex)
Definition OSMutex.c:88
void OSLockMutex(OSMutex *mutex)
Definition OSMutex.c:62
T cLib_calcTimer(T *value)
Definition c_lib.h:74
Definition JASHeapCtrl.h:17
JASDisposer * mDisposer
Definition JASHeapCtrl.h:36
void initRootHeap(void *, u32)
Definition JASHeapCtrl.cpp:23
bool isAllocated()
Definition JASHeapCtrl.h:31
JASHeap * field_0x40
Definition JASHeapCtrl.h:39
JSUTree< JASHeap > mTree
Definition JASHeapCtrl.h:34
OSMutex mMutex
Definition JASHeapCtrl.h:35
JASHeap * getTailHeap()
Definition JASHeapCtrl.cpp:170
u32 mSize
Definition JASHeapCtrl.h:38
bool allocTail(JASHeap *, u32)
Definition JASHeapCtrl.cpp:90
void insertChild(JASHeap *, JASHeap *, void *, u32, bool)
Definition JASHeapCtrl.cpp:147
u32 getSize()
Definition JASHeapCtrl.h:32
bool alloc(JASHeap *, u32)
Definition JASHeapCtrl.cpp:32
bool free()
Definition JASHeapCtrl.cpp:111
u32 getTailOffset()
Definition JASHeapCtrl.cpp:185
u8 * mBase
Definition JASHeapCtrl.h:37
void * getBase()
Definition JASHeapCtrl.h:30
~JASHeap()
Definition JASHeapCtrl.h:28
u32 getCurOffset()
Definition JASHeapCtrl.cpp:193
Definition JASHeapCtrl.h:107
void * alloc(u32 size)
Definition JASHeapCtrl.h:185
JASMemChunkPool()
Definition JASHeapCtrl.h:156
MemoryChunk * field_0x18
Definition JASHeapCtrl.h:218
bool createNewChunk()
Definition JASHeapCtrl.h:162
void free(void *ptr)
Definition JASHeapCtrl.h:198
OSMutex mMutex
Definition JASHeapCtrl.h:217
Definition JASHeapCtrl.h:269
void newMemPool(int param_0)
Definition JASHeapCtrl.h:271
void * alloc(size_t count)
Definition JASHeapCtrl.h:276
void free(void *ptr, u32 param_1)
Definition JASHeapCtrl.h:281
Definition JASHeapCtrl.h:95
void newMemPool(int param_0)
Definition JASHeapCtrl.h:97
void free(void *ptr, u32 n)
Definition JASHeapCtrl.h:99
void * alloc(u32 n)
Definition JASHeapCtrl.h:98
Definition JASHeapCtrl.h:292
static void newMemPool(int n)
Definition JASHeapCtrl.h:306
static JASMemPool_MultiThreaded< T > * getMemPool()
Definition JASHeapCtrl.h:311
Definition JASHeapCtrl.h:239
static JASMemPool< T > * getMemPool()
Definition JASHeapCtrl.h:258
static void newMemPool(int param_0)
Definition JASHeapCtrl.h:252
Definition JKRHeap.h:16
static JKRHeap * getSystemHeap()
Definition JKRHeap.h:153
Definition JKRSolidHeap.h:10
Definition JSUList.h:186
Definition JASAudioThread.cpp:41
n
Definition e_fmod.c:112
static const double T[]
Definition k_tan.c:106
Definition JASHeapCtrl.h:221
void setupAramHeap(u32, u32)
Definition JASHeapCtrl.cpp:289
JASMemChunkPool< 1024, JASThreadingModel::ObjectLevelLockable > * sCommandHeap
Definition JASHeapCtrl.cpp:262
u32 sAramBase
Definition JASHeapCtrl.cpp:256
JKRHeap * getSystemHeap()
Definition JASHeapCtrl.cpp:276
JASHeap audioAramHeap
Definition JASHeapCtrl.cpp:286
JKRHeap * sSystemHeap
Definition JASHeapCtrl.cpp:259
JASMemChunkPool< 1024, JASThreadingModel::ObjectLevelLockable > * getCommandHeap()
Definition JASHeapCtrl.cpp:281
void setupRootHeap(JKRSolidHeap *, u32)
Definition JASHeapCtrl.cpp:266
JASHeap * getAramHeap()
Definition JASHeapCtrl.cpp:295
Definition JASHeapCtrl.h:60
Definition JASWaveArcLoader.h:15
Definition JASHeapCtrl.h:46
~JASGenericMemPool()
Definition JASHeapCtrl.cpp:208
u32 usedMemCount
Definition JASHeapCtrl.h:56
u32 freeMemCount
Definition JASHeapCtrl.h:54
u32 totalMemCount
Definition JASHeapCtrl.h:55
void * field_0x0
Definition JASHeapCtrl.h:53
void newMemPool(u32, int)
Definition JASHeapCtrl.cpp:222
void free(void *, u32)
Definition JASHeapCtrl.cpp:247
JASGenericMemPool()
Definition JASHeapCtrl.cpp:200
void * alloc(u32)
Definition JASHeapCtrl.cpp:233
Definition JASHeapCtrl.h:108
u32 getFreeSize()
Definition JASHeapCtrl.h:142
void revive()
Definition JASHeapCtrl.h:146
u8 mBuffer[ChunkSize]
Definition JASHeapCtrl.h:153
u32 mUsedSize
Definition JASHeapCtrl.h:151
MemoryChunk(MemoryChunk *nextChunk)
Definition JASHeapCtrl.h:109
MemoryChunk * mNextChunk
Definition JASHeapCtrl.h:150
void setNextChunk(MemoryChunk *chunk)
Definition JASHeapCtrl.h:138
u32 mChunks
Definition JASHeapCtrl.h:152
bool isEmpty()
Definition JASHeapCtrl.h:134
void free()
Definition JASHeapCtrl.h:130
void * alloc(u32 size)
Definition JASHeapCtrl.h:123
MemoryChunk * getNextChunk()
Definition JASHeapCtrl.h:119
bool checkArea(void *ptr)
Definition JASHeapCtrl.h:115
~Lock()
Definition JASHeapCtrl.h:65
BOOL field_0x0
Definition JASHeapCtrl.h:67
Lock(const A0 &param_0)
Definition JASHeapCtrl.h:64
Definition JASHeapCtrl.h:62
~Lock()
Definition JASHeapCtrl.h:81
Lock(OSMutex *mutex)
Definition JASHeapCtrl.h:76
OSMutex * mMutex
Definition JASHeapCtrl.h:85
Definition JASHeapCtrl.h:72
Definition OSMutex.h:10
int BOOL
Definition types.h:27
unsigned long u32
Definition types.h:10
unsigned char u8
Definition types.h:8