Adopt the deferred span cache list, optionally extracting the first single span for immediate re-use
| 1591 | |
| 1592 | //! Adopt the deferred span cache list, optionally extracting the first single span for immediate re-use |
| 1593 | static 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 | |
| 1635 | static void |
| 1636 | _rpmalloc_heap_unmap(heap_t* heap) { |
no test coverage detected