| 2373 | |
| 2374 | |
| 2375 | void MemPool::releaseMemory(void* object, bool flagExtent) noexcept |
| 2376 | { |
| 2377 | if (object) |
| 2378 | { |
| 2379 | MemBlock* block = (MemBlock*) ((UCHAR*) object - offsetof(MemBlock, body)); |
| 2380 | MemPool* pool = block->pool; |
| 2381 | |
| 2382 | #ifdef VALIDATE_POOL |
| 2383 | MutexLockGuard guard(pool->mutex, "MemPool::releaseMemory"); |
| 2384 | #endif |
| 2385 | if (flagExtent) |
| 2386 | block->resetExtent(); |
| 2387 | |
| 2388 | #ifdef USE_VALGRIND |
| 2389 | // Synchronize delayed free queue using pool mutex |
| 2390 | MutexLockGuard guard(pool->mutex, "MemPool::deallocate USE_VALGRIND"); |
| 2391 | |
| 2392 | // Notify Valgrind that block is freed from the pool |
| 2393 | VALGRIND_MEMPOOL_FREE(pool, object); |
| 2394 | |
| 2395 | // block is placed in delayed buffer - mark as NOACCESS for that time |
| 2396 | VALGRIND_MAKE_MEM_NOACCESS(block, block->getSize()); |
| 2397 | |
| 2398 | // Extend circular buffer if possible |
| 2399 | if (pool->delayedFreeCount < FB_NELEM(pool->delayedFree)) |
| 2400 | { |
| 2401 | pool->delayedFree[pool->delayedFreeCount] = block; |
| 2402 | pool->delayedFreeCount++; |
| 2403 | return; |
| 2404 | } |
| 2405 | |
| 2406 | // Shift circular buffer pushing out oldest item |
| 2407 | MemBlock* requested_block = block; |
| 2408 | |
| 2409 | block = pool->delayedFree[pool->delayedFreePos]; |
| 2410 | object = &block->body; |
| 2411 | |
| 2412 | // Replace element in circular buffer |
| 2413 | pool->delayedFree[pool->delayedFreePos] = requested_block; |
| 2414 | |
| 2415 | // Move queue pointer to next element and cycle if needed |
| 2416 | if (++(pool->delayedFreePos) >= FB_NELEM(pool->delayedFree)) |
| 2417 | pool->delayedFreePos = 0; |
| 2418 | #endif |
| 2419 | |
| 2420 | // Re-enable access to MemBlock |
| 2421 | block->valgrindInternal(); |
| 2422 | |
| 2423 | #ifdef DEBUG_GDS_ALLOC |
| 2424 | block->fileName = NULL; |
| 2425 | #endif |
| 2426 | |
| 2427 | // Finally delete it |
| 2428 | pool->releaseBlock(block, !flagExtent); |
| 2429 | } |
| 2430 | } |
| 2431 | |
| 2432 | void MemPool::releaseBlock(MemBlock* block, bool decrUsage) noexcept |
nothing calls this directly
no test coverage detected