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

Function _rpmalloc_heap_cache_adopt_deferred

source/extern/rpmalloc.c:1593–1633  ·  view source on GitHub ↗

Adopt the deferred span cache list, optionally extracting the first single span for immediate re-use

Source from the content-addressed store, hash-verified

1591
1592//! Adopt the deferred span cache list, optionally extracting the first single span for immediate re-use
1593static void
1594_rpmalloc_heap_cache_adopt_deferred(heap_t* heap, span_t** single_span) {
1595 span_t* span = (span_t*)((void*)atomic_exchange_ptr_acquire(&heap->span_free_deferred, 0));
1596 while (span) {
1597 span_t* next_span = (span_t*)span->free_list;
1598 rpmalloc_assert(span->heap == heap, "Span heap pointer corrupted");
1599 if (EXPECTED(span->size_class < SIZE_CLASS_COUNT)) {
1600 rpmalloc_assert(heap->full_span_count, "Heap span counter corrupted");
1601 --heap->full_span_count;
1602 _rpmalloc_stat_dec(&heap->span_use[0].spans_deferred);
1603#if RPMALLOC_FIRST_CLASS_HEAPS
1604 _rpmalloc_span_double_link_list_remove(&heap->full_span[span->size_class], span);
1605#endif
1606 _rpmalloc_stat_dec(&heap->span_use[0].current);
1607 _rpmalloc_stat_dec(&heap->size_class_use[span->size_class].spans_current);
1608 if (single_span && !*single_span)
1609 *single_span = span;
1610 else
1611 _rpmalloc_heap_cache_insert(heap, span);
1612 } else {
1613 if (span->size_class == SIZE_CLASS_HUGE) {
1614 _rpmalloc_deallocate_huge(span);
1615 } else {
1616 rpmalloc_assert(span->size_class == SIZE_CLASS_LARGE, "Span size class invalid");
1617 rpmalloc_assert(heap->full_span_count, "Heap span counter corrupted");
1618 --heap->full_span_count;
1619#if RPMALLOC_FIRST_CLASS_HEAPS
1620 _rpmalloc_span_double_link_list_remove(&heap->large_huge_span, span);
1621#endif
1622 uint32_t idx = span->span_count - 1;
1623 _rpmalloc_stat_dec(&heap->span_use[idx].spans_deferred);
1624 _rpmalloc_stat_dec(&heap->span_use[idx].current);
1625 if (!idx && single_span && !*single_span)
1626 *single_span = span;
1627 else
1628 _rpmalloc_heap_cache_insert(heap, span);
1629 }
1630 }
1631 span = next_span;
1632 }
1633}
1634
1635static void
1636_rpmalloc_heap_unmap(heap_t* heap) {

Callers 6

_rpmalloc_heap_allocateFunction · 0.85
_rpmalloc_heap_releaseFunction · 0.85
_rpmalloc_heap_finalizeFunction · 0.85
_rpmalloc_allocate_hugeFunction · 0.85
rpmalloc_heap_free_allFunction · 0.85

Tested by

no test coverage detected