feature. See also
. The project being documented here (as the example) is the Zig library itself.
Threaded.fileUnlock
fn fileUnlock(userdata: ?*anyopaque, file: File) void
File
Code
fn fileUnlock(userdata: ?*anyopaque, file: File) void {
if (native_os == .wasi) return;
const t: *Threaded = @ptrCast(@alignCast(userdata));
_ = t;
if (is_windows) {
var io_status_block: windows.IO_STATUS_BLOCK = undefined;
while (true) switch (windows.ntdll.NtUnlockFile(
file.handle,
&io_status_block,
&windows_lock_range_off,
&windows_lock_range_len,
0,
)) {
.SUCCESS => return,
.CANCELLED => continue,
.RANGE_NOT_LOCKED => if (is_debug) unreachable else return,
.ACCESS_VIOLATION => if (is_debug) unreachable else return,
else => if (is_debug) unreachable else return,
};
}
while (true) {
switch (posix.errno(posix.system.flock(file.handle, posix.LOCK.UN))) {
.SUCCESS => return,
.CANCELED, .INTR => continue,
.AGAIN => return assert(!is_debug),
.BADF => return assert(!is_debug),
.INVAL => return assert(!is_debug),
.NOLCK => return assert(!is_debug),
.OPNOTSUPP => return assert(!is_debug),
else => return assert(!is_debug),
}
}
}