| 46 | } |
| 47 | |
| 48 | mi_decl_noinline static void* mi_segment_cache_pop_ex( |
| 49 | bool all_suitable, |
| 50 | size_t size, mi_commit_mask_t* commit_mask, |
| 51 | mi_commit_mask_t* decommit_mask, bool* large, bool* is_pinned, bool* is_zero, |
| 52 | mi_arena_id_t _req_arena_id, size_t* memid, mi_os_tld_t* tld) |
| 53 | { |
| 54 | #ifdef MI_CACHE_DISABLE |
| 55 | return NULL; |
| 56 | #else |
| 57 | |
| 58 | // only segment blocks |
| 59 | if (size != MI_SEGMENT_SIZE) return NULL; |
| 60 | |
| 61 | // numa node determines start field |
| 62 | const int numa_node = _mi_os_numa_node(tld); |
| 63 | size_t start_field = 0; |
| 64 | if (numa_node > 0) { |
| 65 | start_field = (MI_CACHE_FIELDS / _mi_os_numa_node_count())*numa_node; |
| 66 | if (start_field >= MI_CACHE_FIELDS) start_field = 0; |
| 67 | } |
| 68 | |
| 69 | // find an available slot |
| 70 | mi_bitmap_index_t bitidx = 0; |
| 71 | bool claimed = false; |
| 72 | mi_arena_id_t req_arena_id = _req_arena_id; |
| 73 | mi_bitmap_pred_fun_t pred_fun = (all_suitable ? NULL : &mi_segment_cache_is_suitable); // cannot pass NULL as the arena may be exclusive itself; todo: do not put exclusive arenas in the cache? |
| 74 | |
| 75 | if (*large) { // large allowed? |
| 76 | claimed = _mi_bitmap_try_find_from_claim_pred(cache_available_large, MI_CACHE_FIELDS, start_field, 1, pred_fun, &req_arena_id, &bitidx); |
| 77 | if (claimed) *large = true; |
| 78 | } |
| 79 | if (!claimed) { |
| 80 | claimed = _mi_bitmap_try_find_from_claim_pred (cache_available, MI_CACHE_FIELDS, start_field, 1, pred_fun, &req_arena_id, &bitidx); |
| 81 | if (claimed) *large = false; |
| 82 | } |
| 83 | |
| 84 | if (!claimed) return NULL; |
| 85 | |
| 86 | // found a slot |
| 87 | mi_cache_slot_t* slot = &cache[mi_bitmap_index_bit(bitidx)]; |
| 88 | void* p = slot->p; |
| 89 | *memid = slot->memid; |
| 90 | *is_pinned = slot->is_pinned; |
| 91 | *is_zero = false; |
| 92 | *commit_mask = slot->commit_mask; |
| 93 | *decommit_mask = slot->decommit_mask; |
| 94 | slot->p = NULL; |
| 95 | mi_atomic_storei64_release(&slot->expire,(mi_msecs_t)0); |
| 96 | |
| 97 | // mark the slot as free again |
| 98 | mi_assert_internal(_mi_bitmap_is_claimed(cache_inuse, MI_CACHE_FIELDS, 1, bitidx)); |
| 99 | _mi_bitmap_unclaim(cache_inuse, MI_CACHE_FIELDS, 1, bitidx); |
| 100 | return p; |
| 101 | #endif |
| 102 | } |
| 103 | |
| 104 | |
| 105 | mi_decl_noinline void* _mi_segment_cache_pop(size_t size, mi_commit_mask_t* commit_mask, mi_commit_mask_t* decommit_mask, bool* large, bool* is_pinned, bool* is_zero, mi_arena_id_t _req_arena_id, size_t* memid, mi_os_tld_t* tld) |
no test coverage detected