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 › Dispatch › Futex › Waiter › tryAdd Private Function tryAdd Doc Source 1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539 fn tryAdd (waiter : *Waiter ) Cancelable .RequestedError !void {
if (@atomicLoad (u32 , waiter .ptr , .monotonic ) != waiter .expected )
return error .CancelRequested ;
try waiter .cancelable .enter (waiter .sleeper .fiber );
const futex = waiter .futex ;
switch (waiter .timeout ) {
.FOREVER => {},
else => |timeout | {
const timer = c .dispatch .source_create (.TIMER , 0 , .none , futex .queue ) orelse {
log .warn ("failed to create timer for futex timeout" , .{});
return error .CancelRequested ;
};
timer .as_object ().set_context (waiter );
timer .set_event_handler (&timedOut );
timer .set_cancel_handler (&wake );
timer .set_timer (timeout , c .dispatch .TIME_FOREVER , waiter .leeway );
timer .as_object ().activate ();
waiter .timer = timer ;
},
}
futex .waiters .append (&waiter .node );
}