feature. See also
. The project being documented here (as the example) is the Zig library itself.
SafeAllocator.advanceBucketAlloc
fn advanceBucketAlloc(
s: *SafeAllocator,
old: *AllocFooter,
new_start: u32,
start_moved: bool,
alignment: Alignment,
new_len: usize,
ra: usize,
) bool
File
Code
fn advanceBucketAlloc(
s: *SafeAllocator,
old: *AllocFooter,
new_start: u32,
start_moved: bool,
alignment: Alignment,
new_len: usize,
ra: usize,
) bool {
assert(AllocFooter.allocAlign(alignment).check(new_start));
const b: *Bucket = .of(s, @ptrCast(old));
const old_is_extended = old.isExtended();
const old_footer_len = AllocFooter.lenBucket(s, old_is_extended);
const old_fill: u32 = @intCast(Bucket.fillAt(s, @ptrCast(old)) + old_footer_len);
const new_is_extended = old_is_extended or start_moved or
AllocFooter.requiresExtended(new_len, alignment);
const new_footer_len = AllocFooter.lenBucket(s, new_is_extended);
const new_fill: u32 = @intCast(new_start + AllocFooter.allocOffset(new_len) + new_footer_len);
assert(old_fill <= new_fill);
if (new_fill > s.bucketSize()) {
return false;
}
if (old_fill == new_fill or @cmpxchgStrong(
Bucket.Fill,
&b.fill,
.{ .last_is_extended = old_is_extended, .at = @intCast(old_fill) },
.{ .last_is_extended = new_is_extended, .at = @intCast(new_fill) },
.monotonic,
.monotonic,
) != null) {
return false;
}
_ = AllocFooter.populate(
@alignCast(b.bytes(s)[new_start..new_fill]),
new_len,
alignment,
ra,
new_is_extended,
old.data.prev_extended,
.{ .bucket_prev = old.bucketPrev(b, s) },
s,
);
b.alloc_count.fenceAcqRel();
return true;
}