MCPcopy Create free account
hub / github.com/beefytech/Beef / bitmap_init

Function bitmap_init

BeefRT/JEMalloc/src/bitmap.c:43–80  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

41}
42
43void
44bitmap_init(bitmap_t *bitmap, const bitmap_info_t *binfo, bool fill) {
45 size_t extra;
46 unsigned i;
47
48 /*
49 * Bits are actually inverted with regard to the external bitmap
50 * interface.
51 */
52
53 if (fill) {
54 /* The "filled" bitmap starts out with all 0 bits. */
55 memset(bitmap, 0, bitmap_size(binfo));
56 return;
57 }
58
59 /*
60 * The "empty" bitmap starts out with all 1 bits, except for trailing
61 * unused bits (if any). Note that each group uses bit 0 to correspond
62 * to the first logical bit in the group, so extra bits are the most
63 * significant bits of the last group.
64 */
65 memset(bitmap, 0xffU, bitmap_size(binfo));
66 extra = (BITMAP_GROUP_NBITS - (binfo->nbits & BITMAP_GROUP_NBITS_MASK))
67 & BITMAP_GROUP_NBITS_MASK;
68 if (extra != 0) {
69 bitmap[binfo->levels[1].group_offset - 1] >>= extra;
70 }
71 for (i = 1; i < binfo->nlevels; i++) {
72 size_t group_count = binfo->levels[i].group_offset -
73 binfo->levels[i-1].group_offset;
74 extra = (BITMAP_GROUP_NBITS - (group_count &
75 BITMAP_GROUP_NBITS_MASK)) & BITMAP_GROUP_NBITS_MASK;
76 if (extra != 0) {
77 bitmap[binfo->levels[i+1].group_offset - 1] >>= extra;
78 }
79 }
80}
81
82#else /* BITMAP_USE_TREE */
83

Callers 1

arena_slab_allocFunction · 0.85

Calls 1

bitmap_sizeFunction · 0.85

Tested by

no test coverage detected