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 library itself.
Zig › std/ › Io/ › Threaded.zig › cancel
cancel
Threaded.cancel
fn cancel (
userdata : ?*anyopaque ,
any_future : *Io .AnyFuture ,
result : []u8 ,
result_alignment : Alignment ,
) void
File
Code
fn cancel (
userdata : ?*anyopaque ,
any_future : *Io .AnyFuture ,
result : []u8 ,
result_alignment : Alignment ,
) void {
_ = result_alignment ;
if (builtin .single_threaded ) unreachable ;
const t : *Threaded = @ptrCast (@alignCast (userdata ));
const future : *Future = @ptrCast (@alignCast (any_future ));
var num_completed : std .atomic .Value (u32 ) = .init (0 );
future .awaiter = &num_completed ;
const pre_cancel_status = future .status .fetchOr (.{
.tag = .pending_canceled ,
.thread = .null ,
}, .acq_rel );
switch (pre_cancel_status .tag ) {
.pending => {
const working_thread = pre_cancel_status .thread .unpack ();
future .waitForCancelWithSignaling (t , &num_completed , @alignCast (working_thread ));
},
.pending_awaited => unreachable ,
.pending_canceled => unreachable ,
.done => {},
}
@memcpy (result , future .resultPointer ());
future .destroy (t .allocator );
}