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 › Group › lock Private Function lock Doc Source Private Function std.Io.Dispatch.Group.lock
fn lock (group : Group , ev : *Evented ) void Params File Io/Dispatch.zig: 1162
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195 fn lock (group : Group , ev : *Evented ) void {
const mutex = group .mutexPtr ();
{
const old_state = @atomicRmw (
Group .Mutex ,
mutex ,
.Or ,
.{ .locked = true , .contended = false , .shared2 = 0 },
.acquire ,
);
if (!old_state .locked ) {
@branchHint (.likely );
return ;
}
if (old_state .contended ) {
futexWaitUncancelable (ev , @ptrCast (mutex ), @bitCast (old_state ));
}
}
while (true ) {
var old_state = @atomicRmw (
Group .Mutex ,
mutex ,
.Or ,
.{ .locked = true , .contended = true , .shared2 = 0 },
.acquire ,
);
if (!old_state .locked ) {
@branchHint (.likely );
return ;
}
old_state .contended = true ;
futexWaitUncancelable (ev , @ptrCast (mutex ), @bitCast (old_state ));
}
}