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 › Io › Threaded › cancel Private Function cancel Doc Source Private Function std.Io.Threaded.cancel
fn cancel (
userdata : ?*anyopaque ,
any_future : *Io .AnyFuture ,
result : []u8 ,
result_alignment : Alignment ,
) void Params userdata : ?*anyopaque any_future : *Io .AnyFuture result : []u8 result_alignment : Alignment File Io/Threaded.zig: 2475
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504 fn cancel (
userdata : ?*anyopaque ,
any_future : *Io .AnyFuture ,
result : []u8 ,
result_alignment : Alignment ,
) void {
_ = result_alignment ;
if (builtin .single_threaded ) unreachable ; // nothing to cancel
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 ); // acquire results if complete; release `future.awaiter`
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 , // `await` raced with `await`
.pending_canceled => unreachable , // `await` raced with `cancel`
.done => {},
}
@memcpy (result , future .resultPointer ());
future .destroy (t .allocator );
}