MCPcopy Create free account
hub / github.com/OpenStarbound/OpenStarbound / rpmalloc_finalize

Function rpmalloc_finalize

source/extern/rpmalloc.c:2995–3039  ·  view source on GitHub ↗

Finalize the allocator

Source from the content-addressed store, hash-verified

2993
2994//! Finalize the allocator
2995void
2996rpmalloc_finalize(void) {
2997 rpmalloc_thread_finalize(1);
2998 //rpmalloc_dump_statistics(stdout);
2999
3000 if (_memory_global_reserve) {
3001 atomic_add32(&_memory_global_reserve_master->remaining_spans, -(int32_t)_memory_global_reserve_count);
3002 _memory_global_reserve_master = 0;
3003 _memory_global_reserve_count = 0;
3004 _memory_global_reserve = 0;
3005 }
3006 atomic_store32_release(&_memory_global_lock, 0);
3007
3008 //Free all thread caches and fully free spans
3009 for (size_t list_idx = 0; list_idx < HEAP_ARRAY_SIZE; ++list_idx) {
3010 heap_t* heap = _memory_heaps[list_idx];
3011 while (heap) {
3012 heap_t* next_heap = heap->next_heap;
3013 heap->finalize = 1;
3014 _rpmalloc_heap_global_finalize(heap);
3015 heap = next_heap;
3016 }
3017 }
3018
3019#if ENABLE_GLOBAL_CACHE
3020 //Free global caches
3021 for (size_t iclass = 0; iclass < LARGE_CLASS_COUNT; ++iclass)
3022 _rpmalloc_global_cache_finalize(&_memory_span_cache[iclass]);
3023#endif
3024
3025#if (defined(__APPLE__) || defined(__HAIKU__)) && ENABLE_PRELOAD
3026 pthread_key_delete(_memory_thread_heap);
3027#endif
3028#if defined(_WIN32) && (!defined(BUILD_DYNAMIC_LINK) || !BUILD_DYNAMIC_LINK)
3029 FlsFree(fls_key);
3030 fls_key = 0;
3031#endif
3032#if ENABLE_STATISTICS
3033 //If you hit these asserts you probably have memory leaks (perhaps global scope data doing dynamic allocations) or double frees in your code
3034 rpmalloc_assert(atomic_load32(&_mapped_pages) == 0, "Memory leak detected");
3035 rpmalloc_assert(atomic_load32(&_mapped_pages_os) == 0, "Memory leak detected");
3036#endif
3037
3038 _rpmalloc_initialized = 0;
3039}
3040
3041//! Initialize thread, assign heap
3042extern inline void

Callers 2

DllMainFunction · 0.85
finalizerFunction · 0.85

Calls 6

rpmalloc_thread_finalizeFunction · 0.85
atomic_add32Function · 0.85
atomic_store32_releaseFunction · 0.85
atomic_load32Function · 0.85

Tested by

no test coverage detected