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 › Uring › Fiber › create Private Function create Doc Source Private Function std.Io.Uring.Fiber.create
fn create (ev : *Evented ) error Params File Io/Uring.zig: 273
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303 fn create (ev : *Evented ) error {OutOfMemory }!*Fiber {
const thread : *Thread = .current ();
if (@atomicRmw (?*Fiber , &thread .free_queue , .Xchg , finished , .acquire )) |free_fiber | {
assert (free_fiber != finished );
@atomicStore (?*Fiber , &thread .free_queue , free_fiber .status .free_next , .release );
return free_fiber ;
}
const active_threads = @atomicLoad (u32 , &ev .threads .active , .acquire );
for (0 ..@min (max_steal_free_search , active_threads )) |_ | {
defer thread .steal_free_search_index += 1 ;
if (thread .steal_free_search_index == active_threads ) thread .steal_free_search_index = 0 ;
const steal_free_search_thread =
&ev .threads .allocated [0 ..active_threads ][thread .steal_free_search_index ];
if (steal_free_search_thread == thread ) continue ;
const free_fiber =
@atomicLoad (?*Fiber , &steal_free_search_thread .free_queue , .monotonic ) orelse continue ;
if (free_fiber == finished ) continue ;
if (@cmpxchgWeak (
?*Fiber ,
&steal_free_search_thread .free_queue ,
free_fiber ,
null ,
.acquire ,
.monotonic ,
)) |_ | continue ;
@atomicStore (?*Fiber , &thread .free_queue , free_fiber .status .free_next , .release );
return free_fiber ;
}
@atomicStore (?*Fiber , &thread .free_queue , null , .monotonic );
return @ptrCast (try ev .allocator ().alignedAlloc (u8 , .of (Fiber ), allocation_size ));
}