| 2268 | } |
| 2269 | |
| 2270 | MemBlock* MemPool::allocateInternal(size_t from, size_t& length, bool flagRedirect) |
| 2271 | { |
| 2272 | MutexEnsureUnlock guard(mutex, "MemPool::allocateInternal"); |
| 2273 | guard.enter(); |
| 2274 | |
| 2275 | ++blocksAllocated; |
| 2276 | ++blocksActive; |
| 2277 | |
| 2278 | // If this is a small block, look for it there |
| 2279 | |
| 2280 | MemBlock* block = smallObjects.allocateBlock(this, from, length); |
| 2281 | if (block) |
| 2282 | return block; |
| 2283 | |
| 2284 | // Parent redirection of medium blocks |
| 2285 | |
| 2286 | if (parent_redirect && flagRedirect && length < PARENT_REDIRECT_THRESHOLD) |
| 2287 | { |
| 2288 | guard.leave(); |
| 2289 | block = parent->allocateInternal(from, length, false); |
| 2290 | guard.enter(); |
| 2291 | |
| 2292 | if (block) |
| 2293 | { |
| 2294 | if (parent_redirect) // someone else redirected block in this pool? |
| 2295 | { |
| 2296 | block->setRedirect(); |
| 2297 | |
| 2298 | parentRedirected.push(block); |
| 2299 | if (parentRedirected.getCount() == parentRedirected.getCapacity()) |
| 2300 | parent_redirect = false; |
| 2301 | |
| 2302 | return block; |
| 2303 | } |
| 2304 | else // worst case - very low possibility |
| 2305 | { |
| 2306 | guard.leave(); |
| 2307 | parent->releaseBlock(block, false); |
| 2308 | guard.enter(); |
| 2309 | } |
| 2310 | } |
| 2311 | } |
| 2312 | |
| 2313 | block = mediumObjects.allocateBlock(this, from, length); |
| 2314 | if (block) |
| 2315 | return block; |
| 2316 | |
| 2317 | /* |
| 2318 | * OK, we've got a "big block" on hands. To maximize confusing, the indicated |
| 2319 | * "length" of a free big block is the length of MemHeader plus body*/ |
| 2320 | |
| 2321 | fb_assert(from == 0); |
| 2322 | size_t hunkLength = MemBigHunk::hdrSize() + offsetof(MemBlock, body) + length; |
| 2323 | |
| 2324 | // Allocate the new hunk |
| 2325 | |
| 2326 | MemBigHunk* hunk = new(allocRaw(hunkLength)) MemBigHunk(&bigHunks, hunkLength); |
| 2327 | return hunk->block; |
nothing calls this directly
no test coverage detected