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 › Kqueue › findReadyFiber Private Function findReadyFiber Doc Source Private Function std.Io.Kqueue.findReadyFiber
fn findReadyFiber (k : *Kqueue , thread : *Thread ) ?*Fiber Params File Io/Kqueue.zig: 256
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285 fn findReadyFiber (k : *Kqueue , thread : *Thread ) ?*Fiber {
if (@atomicRmw (?*Fiber , &thread .ready_queue , .Xchg , Fiber .finished , .acquire )) |ready_fiber | {
@atomicStore (?*Fiber , &thread .ready_queue , ready_fiber .queue_next , .release );
ready_fiber .queue_next = null ;
return ready_fiber ;
}
const active_threads = @atomicLoad (u32 , &k .threads .active , .acquire );
for (0 ..@min (max_steal_ready_search , active_threads )) |_ | {
defer thread .steal_ready_search_index += 1 ;
if (thread .steal_ready_search_index == active_threads ) thread .steal_ready_search_index = 0 ;
const steal_ready_search_thread = &k .threads .allocated [0 ..active_threads ][thread .steal_ready_search_index ];
if (steal_ready_search_thread == thread ) continue ;
const ready_fiber = @atomicLoad (?*Fiber , &steal_ready_search_thread .ready_queue , .acquire ) orelse continue ;
if (ready_fiber == Fiber .finished ) continue ;
if (@cmpxchgWeak (
?*Fiber ,
&steal_ready_search_thread .ready_queue ,
ready_fiber ,
null ,
.acquire ,
.monotonic ,
)) |_ | continue ;
@atomicStore (?*Fiber , &thread .ready_queue , ready_fiber .queue_next , .release );
ready_fiber .queue_next = null ;
return ready_fiber ;
}
// couldn't find anything to do, so we are now open for business
@atomicStore (?*Fiber , &thread .ready_queue , null , .monotonic );
return null ;
}