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 library itself.
Zig › std/ › Io/ › Threaded.zig › randomMainThread
randomMainThread
Threaded.randomMainThread
fn randomMainThread (t : *Threaded , buffer : []u8 ) void
File
Code
fn randomMainThread (t : *Threaded , buffer : []u8 ) void {
mutexLock (&t .mutex );
defer mutexUnlock (&t .mutex );
if (!t .csprng .isInitialized ()) {
@branchHint (.unlikely );
var seed : [Csprng .seed_len ]u8 = undefined ;
{
mutexUnlock (&t .mutex );
defer mutexLock (&t .mutex );
const prev = swapCancelProtection (t , .blocked );
defer _ = swapCancelProtection (t , prev );
randomSecure (t , &seed ) catch |err | switch (err ) {
error .Canceled => unreachable ,
error .EntropyUnavailable => fallbackSeed (t , &seed ),
};
}
t .csprng .rng = .init (seed );
}
t .csprng .rng .fill (buffer );
}