MCPcopy Create free account
hub / github.com/FirebirdSQL/firebird / releaseRaw

Method releaseRaw

src/common/classes/alloc.cpp:2602–3102  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2600
2601
2602void MemPool::releaseRaw(bool destroying, void* block, size_t size, ExtentsCache* extentsCache) noexcept
2603{
2604#ifndef USE_VALGRIND
2605 if (extentsCache && (size == DEFAULT_ALLOCATION))
2606 {
2607 MutexLockGuard guard(cache_mutex, "MemPool::releaseRaw");
2608 if (extentsCache->count < MAP_CACHE_SIZE)
2609 {
2610 extentsCache->data[extentsCache->count++] = block;
2611 return;
2612 }
2613 }
2614
2615#define unmapBlockPtr block
2616#define unmapBlockSize size
2617
2618#else
2619 // Set access protection for block to prevent memory from deleted pool being accessed
2620 VALGRIND_MAKE_MEM_NOACCESS(block, size);
2621
2622 size = FB_ALIGN(size, get_map_page_size());
2623
2624 void* unmapBlockPtr = block;
2625 size_t unmapBlockSize = size;
2626
2627 // Employ extents delayed free logic only when pool is destroying.
2628 // In normal case all blocks pass through queue of sufficent length by themselves
2629 if (destroying)
2630 {
2631 // Synchronize delayed free queue using extents mutex
2632 MutexLockGuard guard(cache_mutex, "MemPool::releaseRaw");
2633
2634 // Extend circular buffer if possible
2635 if (delayedExtentCount < FB_NELEM(delayedExtents))
2636 {
2637 DelayedExtent* item = &delayedExtents[delayedExtentCount];
2638 item->memory = block;
2639 item->size = size;
2640 delayedExtentCount++;
2641 return;
2642 }
2643
2644 DelayedExtent* item = &delayedExtents[delayedExtentsPos];
2645
2646 // Set up the block we are going to unmap
2647 unmapBlockPtr = item->memory;
2648 unmapBlockSize = item->size;
2649
2650 // Replace element in circular buffer
2651 item->memory = block;
2652 item->size = size;
2653
2654 // Move queue pointer to next element and cycle if needed
2655 delayedExtentsPos++;
2656 if (delayedExtentsPos >= FB_NELEM(delayedExtents))
2657 delayedExtentsPos = 0;
2658 }
2659#endif

Callers

nothing calls this directly

Calls 5

FB_ALIGNFunction · 0.85
get_map_page_sizeFunction · 0.85
corruptFunction · 0.85
getDefaultMemoryPoolFunction · 0.85
pushFunction · 0.70

Tested by

no test coverage detected