MCPcopy Create free account
hub / github.com/Tracktion/tracktion_engine / _rpmalloc_span_map

Function _rpmalloc_span_map

modules/3rd_party/rpmalloc/rpmalloc.c:1133–1162  ·  view source on GitHub ↗

Map in memory pages for the given number of spans (or use previously reserved pages)

Source from the content-addressed store, hash-verified

1131
1132//! Map in memory pages for the given number of spans (or use previously reserved pages)
1133static span_t*
1134_rpmalloc_span_map(heap_t* heap, size_t span_count) {
1135 if (span_count <= heap->spans_reserved)
1136 return _rpmalloc_span_map_from_reserve(heap, span_count);
1137 span_t* span = 0;
1138 if (_memory_page_size > _memory_span_size) {
1139 // If huge pages, make sure only one thread maps more memory to avoid bloat
1140 while (!atomic_cas32_acquire(&_memory_global_lock, 1, 0))
1141 _rpmalloc_spin();
1142 if (_memory_global_reserve_count >= span_count) {
1143 size_t reserve_count = (!heap->spans_reserved ? DEFAULT_SPAN_MAP_COUNT : span_count);
1144 if (_memory_global_reserve_count < reserve_count)
1145 reserve_count = _memory_global_reserve_count;
1146 span = _rpmalloc_global_get_reserved_spans(reserve_count);
1147 if (span) {
1148 if (reserve_count > span_count) {
1149 span_t* reserved_span = (span_t*)pointer_offset(span, span_count << _memory_span_size_shift);
1150 _rpmalloc_heap_set_reserved_spans(heap, _memory_global_reserve_master, reserved_span, reserve_count - span_count);
1151 }
1152 // Already marked as subspan in _rpmalloc_global_get_reserved_spans
1153 span->span_count = (uint32_t)span_count;
1154 }
1155 }
1156 }
1157 if (!span)
1158 span = _rpmalloc_span_map_aligned_count(heap, span_count);
1159 if (_memory_page_size > _memory_span_size)
1160 atomic_store32_release(&_memory_global_lock, 0);
1161 return span;
1162}
1163
1164//! Unmap memory pages for the given number of spans (or mark as unused if no partial unmappings)
1165static void

Callers 3

_rpmalloc_heap_finalizeFunction · 0.85

Tested by

no test coverage detected