commit f33395ce6a66df517c09037c4a4f1756ef7f6f2e (tree)
parent 716b128a24ffc44a8694f3d61e3d74b5297fd564
Author: Andrew Kelley <andrew@ziglang.org>
Date: Sun, 14 Jul 2024 21:38:05 -0700
std.Progress: add getIpcFd and have_ipc API
This makes advanced use cases possible such as a long-lived child
process whose progress node gets re-attached to a different parent.
Diffstat:
1 file changed, 18 insertions(+), 0 deletions(-)
diff --git a/lib/std/Progress.zig b/lib/std/Progress.zig
@@ -269,6 +269,19 @@ pub const Node = struct {
storageByIndex(index).setIpcFd(fd);
}
+ /// Posix-only. Thread-safe. Assumes the node is storing an IPC file
+ /// descriptor.
+ pub fn getIpcFd(node: Node) ?posix.fd_t {
+ const index = node.index.unwrap() orelse return null;
+ const storage = storageByIndex(index);
+ const int = @atomicLoad(u32, &storage.completed_count, .monotonic);
+ return switch (@typeInfo(posix.fd_t)) {
+ .Int => @bitCast(int),
+ .Pointer => @ptrFromInt(int),
+ else => @compileError("unsupported fd_t of " ++ @typeName(posix.fd_t)),
+ };
+ }
+
fn storageByIndex(index: Node.Index) *Node.Storage {
return &global_progress.node_storage[@intFromEnum(index)];
}
@@ -329,6 +342,11 @@ var default_draw_buffer: [4096]u8 = undefined;
var debug_start_trace = std.debug.Trace.init;
+pub const have_ipc = switch (builtin.os.tag) {
+ .wasi, .freestanding, .windows => false,
+ else => true,
+};
+
const noop_impl = builtin.single_threaded or switch (builtin.os.tag) {
.wasi, .freestanding => true,
else => false,