daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1 | // |
| 2 | // Copyright (c) 2002-2010 The ANGLE Project Authors. All rights reserved. |
| 3 | // Use of this source code is governed by a BSD-style license that can be |
| 4 | // found in the LICENSE file. |
| 5 | // |
| 6 | |
Geoff Lang | 1773282 | 2013-08-29 13:46:49 -0400 | [diff] [blame] | 7 | #include "compiler/translator/PoolAlloc.h" |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 8 | |
Geoff Lang | 44fa759 | 2014-05-30 11:50:07 -0400 | [diff] [blame] | 9 | #include <stdint.h> |
| 10 | #include <stdio.h> |
| 11 | #include <assert.h> |
| 12 | |
Jamie Madill | 438dbcf | 2016-06-17 14:20:05 -0400 | [diff] [blame] | 13 | #include "common/angleutils.h" |
| 14 | #include "common/debug.h" |
| 15 | #include "common/platform.h" |
| 16 | #include "common/tls.h" |
| 17 | #include "compiler/translator/InitializeGlobals.h" |
| 18 | |
Geoff Lang | 44fa759 | 2014-05-30 11:50:07 -0400 | [diff] [blame] | 19 | TLSIndex PoolIndex = TLS_INVALID_INDEX; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 20 | |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 21 | bool InitializePoolIndex() |
| 22 | { |
Geoff Lang | 44fa759 | 2014-05-30 11:50:07 -0400 | [diff] [blame] | 23 | assert(PoolIndex == TLS_INVALID_INDEX); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 24 | |
Geoff Lang | 44fa759 | 2014-05-30 11:50:07 -0400 | [diff] [blame] | 25 | PoolIndex = CreateTLSIndex(); |
| 26 | return PoolIndex != TLS_INVALID_INDEX; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 27 | } |
| 28 | |
| 29 | void FreePoolIndex() |
| 30 | { |
Geoff Lang | 44fa759 | 2014-05-30 11:50:07 -0400 | [diff] [blame] | 31 | assert(PoolIndex != TLS_INVALID_INDEX); |
Alok Priyadarshi | 8156b6b | 2013-09-23 14:56:58 -0400 | [diff] [blame] | 32 | |
Geoff Lang | 44fa759 | 2014-05-30 11:50:07 -0400 | [diff] [blame] | 33 | DestroyTLSIndex(PoolIndex); |
| 34 | PoolIndex = TLS_INVALID_INDEX; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 35 | } |
| 36 | |
Alok Priyadarshi | 8156b6b | 2013-09-23 14:56:58 -0400 | [diff] [blame] | 37 | TPoolAllocator* GetGlobalPoolAllocator() |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 38 | { |
Geoff Lang | 44fa759 | 2014-05-30 11:50:07 -0400 | [diff] [blame] | 39 | assert(PoolIndex != TLS_INVALID_INDEX); |
| 40 | return static_cast<TPoolAllocator*>(GetTLSValue(PoolIndex)); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 41 | } |
| 42 | |
alokp@chromium.org | bafcbaa | 2010-11-23 19:07:43 +0000 | [diff] [blame] | 43 | void SetGlobalPoolAllocator(TPoolAllocator* poolAllocator) |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 44 | { |
Geoff Lang | 44fa759 | 2014-05-30 11:50:07 -0400 | [diff] [blame] | 45 | assert(PoolIndex != TLS_INVALID_INDEX); |
| 46 | SetTLSValue(PoolIndex, poolAllocator); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 47 | } |
| 48 | |
| 49 | // |
| 50 | // Implement the functionality of the TPoolAllocator class, which |
| 51 | // is documented in PoolAlloc.h. |
| 52 | // |
Corentin Wallez | 28b6528 | 2016-06-16 07:24:50 -0700 | [diff] [blame] | 53 | TPoolAllocator::TPoolAllocator(int growthIncrement, int allocationAlignment) |
| 54 | : alignment(allocationAlignment), |
| 55 | #if !defined(ANGLE_TRANSLATOR_DISABLE_POOL_ALLOC) |
| 56 | pageSize(growthIncrement), |
| 57 | freeList(0), |
| 58 | inUseList(0), |
| 59 | numCalls(0), |
| 60 | totalBytes(0), |
| 61 | #endif |
| 62 | mLocked(false) |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 63 | { |
alokp@chromium.org | 4e89d23 | 2010-05-14 19:37:21 +0000 | [diff] [blame] | 64 | // |
alokp@chromium.org | 4e89d23 | 2010-05-14 19:37:21 +0000 | [diff] [blame] | 65 | // Adjust alignment to be at least pointer aligned and |
| 66 | // power of 2. |
| 67 | // |
| 68 | size_t minAlign = sizeof(void*); |
| 69 | alignment &= ~(minAlign - 1); |
| 70 | if (alignment < minAlign) |
| 71 | alignment = minAlign; |
| 72 | size_t a = 1; |
| 73 | while (a < alignment) |
| 74 | a <<= 1; |
| 75 | alignment = a; |
| 76 | alignmentMask = a - 1; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 77 | |
Corentin Wallez | 28b6528 | 2016-06-16 07:24:50 -0700 | [diff] [blame] | 78 | #if !defined(ANGLE_TRANSLATOR_DISABLE_POOL_ALLOC) |
| 79 | // |
| 80 | // Don't allow page sizes we know are smaller than all common |
| 81 | // OS page sizes. |
| 82 | // |
| 83 | if (pageSize < 4 * 1024) |
| 84 | pageSize = 4 * 1024; |
| 85 | |
| 86 | // |
| 87 | // A large currentPageOffset indicates a new page needs to |
| 88 | // be obtained to allocate memory. |
| 89 | // |
| 90 | currentPageOffset = pageSize; |
| 91 | |
alokp@chromium.org | 4e89d23 | 2010-05-14 19:37:21 +0000 | [diff] [blame] | 92 | // |
| 93 | // Align header skip |
| 94 | // |
| 95 | headerSkip = minAlign; |
| 96 | if (headerSkip < sizeof(tHeader)) { |
| 97 | headerSkip = (sizeof(tHeader) + alignmentMask) & ~alignmentMask; |
| 98 | } |
Corentin Wallez | 28b6528 | 2016-06-16 07:24:50 -0700 | [diff] [blame] | 99 | #else // !defined(ANGLE_TRANSLATOR_DISABLE_POOL_ALLOC) |
| 100 | mStack.push_back({}); |
| 101 | #endif |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 102 | } |
| 103 | |
| 104 | TPoolAllocator::~TPoolAllocator() |
| 105 | { |
Corentin Wallez | 28b6528 | 2016-06-16 07:24:50 -0700 | [diff] [blame] | 106 | #if !defined(ANGLE_TRANSLATOR_DISABLE_POOL_ALLOC) |
alokp@chromium.org | bafcbaa | 2010-11-23 19:07:43 +0000 | [diff] [blame] | 107 | while (inUseList) { |
| 108 | tHeader* next = inUseList->nextPage; |
| 109 | inUseList->~tHeader(); |
| 110 | delete [] reinterpret_cast<char*>(inUseList); |
| 111 | inUseList = next; |
alokp@chromium.org | 4e89d23 | 2010-05-14 19:37:21 +0000 | [diff] [blame] | 112 | } |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 113 | |
alokp@chromium.org | bafcbaa | 2010-11-23 19:07:43 +0000 | [diff] [blame] | 114 | // We should not check the guard blocks |
alokp@chromium.org | 4e89d23 | 2010-05-14 19:37:21 +0000 | [diff] [blame] | 115 | // here, because we did it already when the block was |
| 116 | // placed into the free list. |
| 117 | // |
| 118 | while (freeList) { |
| 119 | tHeader* next = freeList->nextPage; |
| 120 | delete [] reinterpret_cast<char*>(freeList); |
| 121 | freeList = next; |
| 122 | } |
Corentin Wallez | 28b6528 | 2016-06-16 07:24:50 -0700 | [diff] [blame] | 123 | #else // !defined(ANGLE_TRANSLATOR_DISABLE_POOL_ALLOC) |
| 124 | for (auto &allocs : mStack) |
| 125 | { |
| 126 | for (auto alloc : allocs) |
| 127 | { |
| 128 | free(alloc); |
| 129 | } |
| 130 | } |
| 131 | mStack.clear(); |
| 132 | #endif |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 133 | } |
| 134 | |
| 135 | // Support MSVC++ 6.0 |
| 136 | const unsigned char TAllocation::guardBlockBeginVal = 0xfb; |
| 137 | const unsigned char TAllocation::guardBlockEndVal = 0xfe; |
| 138 | const unsigned char TAllocation::userDataFill = 0xcd; |
| 139 | |
alokp@chromium.org | b1e8c6f | 2010-05-12 18:35:53 +0000 | [diff] [blame] | 140 | #ifdef GUARD_BLOCKS |
alokp@chromium.org | 4e89d23 | 2010-05-14 19:37:21 +0000 | [diff] [blame] | 141 | const size_t TAllocation::guardBlockSize = 16; |
alokp@chromium.org | b1e8c6f | 2010-05-12 18:35:53 +0000 | [diff] [blame] | 142 | #else |
alokp@chromium.org | 4e89d23 | 2010-05-14 19:37:21 +0000 | [diff] [blame] | 143 | const size_t TAllocation::guardBlockSize = 0; |
alokp@chromium.org | b1e8c6f | 2010-05-12 18:35:53 +0000 | [diff] [blame] | 144 | #endif |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 145 | |
| 146 | // |
| 147 | // Check a single guard block for damage |
| 148 | // |
| 149 | void TAllocation::checkGuardBlock(unsigned char* blockMem, unsigned char val, const char* locText) const |
| 150 | { |
daniel@transgaming.com | b969cc5 | 2011-03-15 18:23:59 +0000 | [diff] [blame] | 151 | #ifdef GUARD_BLOCKS |
alokp@chromium.org | 4e89d23 | 2010-05-14 19:37:21 +0000 | [diff] [blame] | 152 | for (size_t x = 0; x < guardBlockSize; x++) { |
| 153 | if (blockMem[x] != val) { |
| 154 | char assertMsg[80]; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 155 | |
alokp@chromium.org | 4e89d23 | 2010-05-14 19:37:21 +0000 | [diff] [blame] | 156 | // We don't print the assert message. It's here just to be helpful. |
apatrick@chromium.org | e431963 | 2012-01-27 22:13:17 +0000 | [diff] [blame] | 157 | #if defined(_MSC_VER) |
kbr@chromium.org | ddb6e8e | 2012-04-25 00:48:13 +0000 | [diff] [blame] | 158 | snprintf(assertMsg, sizeof(assertMsg), "PoolAlloc: Damage %s %Iu byte allocation at 0x%p\n", |
alokp@chromium.org | 4e89d23 | 2010-05-14 19:37:21 +0000 | [diff] [blame] | 159 | locText, size, data()); |
apatrick@chromium.org | e431963 | 2012-01-27 22:13:17 +0000 | [diff] [blame] | 160 | #else |
kbr@chromium.org | ddb6e8e | 2012-04-25 00:48:13 +0000 | [diff] [blame] | 161 | snprintf(assertMsg, sizeof(assertMsg), "PoolAlloc: Damage %s %zu byte allocation at 0x%p\n", |
apatrick@chromium.org | e431963 | 2012-01-27 22:13:17 +0000 | [diff] [blame] | 162 | locText, size, data()); |
| 163 | #endif |
alokp@chromium.org | 4e89d23 | 2010-05-14 19:37:21 +0000 | [diff] [blame] | 164 | assert(0 && "PoolAlloc: Damage in guard block"); |
| 165 | } |
| 166 | } |
daniel@transgaming.com | b969cc5 | 2011-03-15 18:23:59 +0000 | [diff] [blame] | 167 | #endif |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 168 | } |
| 169 | |
| 170 | |
| 171 | void TPoolAllocator::push() |
| 172 | { |
Corentin Wallez | 28b6528 | 2016-06-16 07:24:50 -0700 | [diff] [blame] | 173 | #if !defined(ANGLE_TRANSLATOR_DISABLE_POOL_ALLOC) |
alokp@chromium.org | 4e89d23 | 2010-05-14 19:37:21 +0000 | [diff] [blame] | 174 | tAllocState state = { currentPageOffset, inUseList }; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 175 | |
Corentin Wallez | 28b6528 | 2016-06-16 07:24:50 -0700 | [diff] [blame] | 176 | mStack.push_back(state); |
| 177 | |
alokp@chromium.org | 4e89d23 | 2010-05-14 19:37:21 +0000 | [diff] [blame] | 178 | // |
| 179 | // Indicate there is no current page to allocate from. |
| 180 | // |
| 181 | currentPageOffset = pageSize; |
Corentin Wallez | 28b6528 | 2016-06-16 07:24:50 -0700 | [diff] [blame] | 182 | #else // !defined(ANGLE_TRANSLATOR_DISABLE_POOL_ALLOC) |
| 183 | mStack.push_back({}); |
| 184 | #endif |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 185 | } |
| 186 | |
| 187 | // |
| 188 | // Do a mass-deallocation of all the individual allocations |
| 189 | // that have occurred since the last push(), or since the |
| 190 | // last pop(), or since the object's creation. |
| 191 | // |
| 192 | // The deallocated pages are saved for future allocations. |
| 193 | // |
| 194 | void TPoolAllocator::pop() |
| 195 | { |
Corentin Wallez | 28b6528 | 2016-06-16 07:24:50 -0700 | [diff] [blame] | 196 | if (mStack.size() < 1) |
alokp@chromium.org | 4e89d23 | 2010-05-14 19:37:21 +0000 | [diff] [blame] | 197 | return; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 198 | |
Corentin Wallez | 28b6528 | 2016-06-16 07:24:50 -0700 | [diff] [blame] | 199 | #if !defined(ANGLE_TRANSLATOR_DISABLE_POOL_ALLOC) |
| 200 | tHeader *page = mStack.back().page; |
| 201 | currentPageOffset = mStack.back().offset; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 202 | |
alokp@chromium.org | 4e89d23 | 2010-05-14 19:37:21 +0000 | [diff] [blame] | 203 | while (inUseList != page) { |
| 204 | // invoke destructor to free allocation list |
| 205 | inUseList->~tHeader(); |
| 206 | |
| 207 | tHeader* nextInUse = inUseList->nextPage; |
| 208 | if (inUseList->pageCount > 1) |
| 209 | delete [] reinterpret_cast<char*>(inUseList); |
| 210 | else { |
| 211 | inUseList->nextPage = freeList; |
| 212 | freeList = inUseList; |
| 213 | } |
| 214 | inUseList = nextInUse; |
| 215 | } |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 216 | |
Corentin Wallez | 28b6528 | 2016-06-16 07:24:50 -0700 | [diff] [blame] | 217 | mStack.pop_back(); |
| 218 | #else // !defined(ANGLE_TRANSLATOR_DISABLE_POOL_ALLOC) |
| 219 | for (auto &alloc : mStack.back()) |
| 220 | { |
| 221 | free(alloc); |
| 222 | } |
| 223 | mStack.pop_back(); |
| 224 | #endif |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 225 | } |
| 226 | |
| 227 | // |
| 228 | // Do a mass-deallocation of all the individual allocations |
| 229 | // that have occurred. |
| 230 | // |
| 231 | void TPoolAllocator::popAll() |
| 232 | { |
Corentin Wallez | 28b6528 | 2016-06-16 07:24:50 -0700 | [diff] [blame] | 233 | while (mStack.size() > 0) |
alokp@chromium.org | 4e89d23 | 2010-05-14 19:37:21 +0000 | [diff] [blame] | 234 | pop(); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 235 | } |
| 236 | |
| 237 | void* TPoolAllocator::allocate(size_t numBytes) |
| 238 | { |
Jamie Madill | 438dbcf | 2016-06-17 14:20:05 -0400 | [diff] [blame] | 239 | ASSERT(!mLocked); |
| 240 | |
Corentin Wallez | 28b6528 | 2016-06-16 07:24:50 -0700 | [diff] [blame] | 241 | #if !defined(ANGLE_TRANSLATOR_DISABLE_POOL_ALLOC) |
alokp@chromium.org | 4e89d23 | 2010-05-14 19:37:21 +0000 | [diff] [blame] | 242 | // |
| 243 | // Just keep some interesting statistics. |
| 244 | // |
| 245 | ++numCalls; |
| 246 | totalBytes += numBytes; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 247 | |
shannonwoods@chromium.org | c796484 | 2013-05-30 00:10:41 +0000 | [diff] [blame] | 248 | // If we are using guard blocks, all allocations are bracketed by |
| 249 | // them: [guardblock][allocation][guardblock]. numBytes is how |
| 250 | // much memory the caller asked for. allocationSize is the total |
| 251 | // size including guard blocks. In release build, |
| 252 | // guardBlockSize=0 and this all gets optimized away. |
| 253 | size_t allocationSize = TAllocation::allocationSize(numBytes); |
| 254 | // Detect integer overflow. |
| 255 | if (allocationSize < numBytes) |
| 256 | return 0; |
| 257 | |
alokp@chromium.org | 4e89d23 | 2010-05-14 19:37:21 +0000 | [diff] [blame] | 258 | // |
| 259 | // Do the allocation, most likely case first, for efficiency. |
| 260 | // This step could be moved to be inline sometime. |
| 261 | // |
shannonwoods@chromium.org | c796484 | 2013-05-30 00:10:41 +0000 | [diff] [blame] | 262 | if (allocationSize <= pageSize - currentPageOffset) { |
alokp@chromium.org | 4e89d23 | 2010-05-14 19:37:21 +0000 | [diff] [blame] | 263 | // |
| 264 | // Safe to allocate from currentPageOffset. |
| 265 | // |
| 266 | unsigned char* memory = reinterpret_cast<unsigned char *>(inUseList) + currentPageOffset; |
| 267 | currentPageOffset += allocationSize; |
| 268 | currentPageOffset = (currentPageOffset + alignmentMask) & ~alignmentMask; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 269 | |
alokp@chromium.org | 4e89d23 | 2010-05-14 19:37:21 +0000 | [diff] [blame] | 270 | return initializeAllocation(inUseList, memory, numBytes); |
| 271 | } |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 272 | |
shannonwoods@chromium.org | c796484 | 2013-05-30 00:10:41 +0000 | [diff] [blame] | 273 | if (allocationSize > pageSize - headerSkip) { |
alokp@chromium.org | 4e89d23 | 2010-05-14 19:37:21 +0000 | [diff] [blame] | 274 | // |
| 275 | // Do a multi-page allocation. Don't mix these with the others. |
| 276 | // The OS is efficient and allocating and free-ing multiple pages. |
| 277 | // |
| 278 | size_t numBytesToAlloc = allocationSize + headerSkip; |
shannonwoods@chromium.org | c796484 | 2013-05-30 00:10:41 +0000 | [diff] [blame] | 279 | // Detect integer overflow. |
| 280 | if (numBytesToAlloc < allocationSize) |
| 281 | return 0; |
| 282 | |
alokp@chromium.org | 4e89d23 | 2010-05-14 19:37:21 +0000 | [diff] [blame] | 283 | tHeader* memory = reinterpret_cast<tHeader*>(::new char[numBytesToAlloc]); |
| 284 | if (memory == 0) |
| 285 | return 0; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 286 | |
alokp@chromium.org | 4e89d23 | 2010-05-14 19:37:21 +0000 | [diff] [blame] | 287 | // Use placement-new to initialize header |
| 288 | new(memory) tHeader(inUseList, (numBytesToAlloc + pageSize - 1) / pageSize); |
| 289 | inUseList = memory; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 290 | |
alokp@chromium.org | 4e89d23 | 2010-05-14 19:37:21 +0000 | [diff] [blame] | 291 | currentPageOffset = pageSize; // make next allocation come from a new page |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 292 | |
alokp@chromium.org | 4e89d23 | 2010-05-14 19:37:21 +0000 | [diff] [blame] | 293 | // No guard blocks for multi-page allocations (yet) |
| 294 | return reinterpret_cast<void*>(reinterpret_cast<uintptr_t>(memory) + headerSkip); |
| 295 | } |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 296 | |
alokp@chromium.org | 4e89d23 | 2010-05-14 19:37:21 +0000 | [diff] [blame] | 297 | // |
| 298 | // Need a simple page to allocate from. |
| 299 | // |
| 300 | tHeader* memory; |
| 301 | if (freeList) { |
| 302 | memory = freeList; |
| 303 | freeList = freeList->nextPage; |
| 304 | } else { |
| 305 | memory = reinterpret_cast<tHeader*>(::new char[pageSize]); |
| 306 | if (memory == 0) |
| 307 | return 0; |
| 308 | } |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 309 | |
alokp@chromium.org | 4e89d23 | 2010-05-14 19:37:21 +0000 | [diff] [blame] | 310 | // Use placement-new to initialize header |
| 311 | new(memory) tHeader(inUseList, 1); |
| 312 | inUseList = memory; |
| 313 | |
| 314 | unsigned char* ret = reinterpret_cast<unsigned char *>(inUseList) + headerSkip; |
| 315 | currentPageOffset = (headerSkip + allocationSize + alignmentMask) & ~alignmentMask; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 316 | |
alokp@chromium.org | 4e89d23 | 2010-05-14 19:37:21 +0000 | [diff] [blame] | 317 | return initializeAllocation(inUseList, ret, numBytes); |
Corentin Wallez | 28b6528 | 2016-06-16 07:24:50 -0700 | [diff] [blame] | 318 | #else // !defined(ANGLE_TRANSLATOR_DISABLE_POOL_ALLOC) |
| 319 | void *alloc = malloc(numBytes + alignmentMask); |
| 320 | mStack.back().push_back(alloc); |
| 321 | |
| 322 | intptr_t intAlloc = reinterpret_cast<intptr_t>(alloc); |
| 323 | intAlloc = (intAlloc + alignmentMask) & ~alignmentMask; |
| 324 | return reinterpret_cast<void *>(intAlloc); |
| 325 | #endif |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 326 | } |
| 327 | |
Jamie Madill | 438dbcf | 2016-06-17 14:20:05 -0400 | [diff] [blame] | 328 | void TPoolAllocator::lock() |
| 329 | { |
| 330 | ASSERT(!mLocked); |
| 331 | mLocked = true; |
| 332 | } |
| 333 | |
| 334 | void TPoolAllocator::unlock() |
| 335 | { |
| 336 | ASSERT(mLocked); |
| 337 | mLocked = false; |
| 338 | } |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 339 | |
| 340 | // |
| 341 | // Check all allocations in a list for damage by calling check on each. |
| 342 | // |
| 343 | void TAllocation::checkAllocList() const |
| 344 | { |
alokp@chromium.org | 4e89d23 | 2010-05-14 19:37:21 +0000 | [diff] [blame] | 345 | for (const TAllocation* alloc = this; alloc != 0; alloc = alloc->prevAlloc) |
| 346 | alloc->check(); |
daniel@transgaming.com | b969cc5 | 2011-03-15 18:23:59 +0000 | [diff] [blame] | 347 | } |