Zig 0.17.0-dev (Split by item) This is an example of documentation generated by
ZigDoc , an alternative to Zig's built-in
Auto Doc feature. See also
examples in other modes/formats . The project being documented here (as the example) is the Zig standard library.
std › heap › FixedBufferAllocator › threadSafeFree Private Function threadSafeFree Doc Source Private Function std.heap.FixedBufferAllocator.threadSafeFree
fn threadSafeFree (ctx : *anyopaque , memory : []u8 , alignment : mem .Alignment , ret_addr : usize ) void Params ctx : *anyopaque memory : []u8 alignment : mem .Alignment ret_addr : usize File heap/FixedBufferAllocator.zig: 200
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224 fn threadSafeFree (ctx : *anyopaque , memory : []u8 , alignment : mem .Alignment , ret_addr : usize ) void {
const fba : *FixedBufferAllocator = @ptrCast (@alignCast (ctx ));
_ = alignment ;
_ = ret_addr ;
assert (memory .len > 0 );
const cur_end_index = @atomicLoad (usize , &fba .end_index , .monotonic );
if (fba .buffer .ptr + cur_end_index != memory .ptr + memory .len ) {
// Not the most recent allocation; we cannot free it.
return ;
}
const new_end_index = cur_end_index - memory .len ;
assert (fba .buffer .ptr + new_end_index == memory .ptr );
_ = @cmpxchgStrong (
usize ,
&fba .end_index ,
cur_end_index ,
new_end_index ,
.release , // release freed memory
.monotonic ,
);
}