MCPcopy Create free account
hub / github.com/CppCXY/EmmyLuaCodeStyle / _mi_bitmap_claim_across

Function _mi_bitmap_claim_across

3rd/mimalloc-2.0.9/src/bitmap.c:351–375  ·  view source on GitHub ↗

Set `count` bits at `bitmap_idx` to 1 atomically Returns `true` if all `count` bits were 0 previously. `any_zero` is `true` if there was at least one zero bit.

Source from the content-addressed store, hash-verified

349// Set `count` bits at `bitmap_idx` to 1 atomically
350// Returns `true` if all `count` bits were 0 previously. `any_zero` is `true` if there was at least one zero bit.
351bool _mi_bitmap_claim_across(mi_bitmap_t bitmap, size_t bitmap_fields, size_t count, mi_bitmap_index_t bitmap_idx, bool* pany_zero) {
352 size_t idx = mi_bitmap_index_field(bitmap_idx);
353 size_t pre_mask;
354 size_t mid_mask;
355 size_t post_mask;
356 size_t mid_count = mi_bitmap_mask_across(bitmap_idx, bitmap_fields, count, &pre_mask, &mid_mask, &post_mask);
357 bool all_zero = true;
358 bool any_zero = false;
359 _Atomic(size_t)*field = &bitmap[idx];
360 size_t prev = mi_atomic_or_acq_rel(field++, pre_mask);
361 if ((prev & pre_mask) != 0) all_zero = false;
362 if ((prev & pre_mask) != pre_mask) any_zero = true;
363 while (mid_count-- > 0) {
364 prev = mi_atomic_or_acq_rel(field++, mid_mask);
365 if ((prev & mid_mask) != 0) all_zero = false;
366 if ((prev & mid_mask) != mid_mask) any_zero = true;
367 }
368 if (post_mask!=0) {
369 prev = mi_atomic_or_acq_rel(field, post_mask);
370 if ((prev & post_mask) != 0) all_zero = false;
371 if ((prev & post_mask) != post_mask) any_zero = true;
372 }
373 if (pany_zero != NULL) *pany_zero = any_zero;
374 return all_zero;
375}
376
377
378// Returns `true` if all `count` bits were 1.

Callers 1

mi_arena_alloc_fromFunction · 0.85

Calls 2

mi_bitmap_index_fieldFunction · 0.85
mi_bitmap_mask_acrossFunction · 0.85

Tested by

no test coverage detected