From 03cd14d662cf977e515129b8ec35992e34054c07 Mon Sep 17 00:00:00 2001 From: Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> Date: Fri, 9 Feb 2024 17:49:40 -0800 Subject: [PATCH] wip --- src/async/posix_event_loop.zig | 21 ++++++++++++++++++++- src/bun.js/api/bun/process.zig | 4 ++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/async/posix_event_loop.zig b/src/async/posix_event_loop.zig index d0157453a5..99bce87223 100644 --- a/src/async/posix_event_loop.zig +++ b/src/async/posix_event_loop.zig @@ -208,7 +208,12 @@ pub const FilePoll = struct { poll.flags = flags; } + pub fn format(poll: *const FilePoll, comptime _: []const u8, _: std.fmt.FormatOptions, writer: anytype) !void { + try writer.print("FilePoll({}) = {}", .{ poll.fd, Flags.Formatter{ .data = poll.flags } }); + } + pub fn onKQueueEvent(poll: *FilePoll, _: *Loop, kqueue_event: *const std.os.system.kevent64_s) void { + log("onKQueueEvent: {}", .{poll}); if (KQueueGenerationNumber != u0) std.debug.assert(poll.generation_number == kqueue_event.ext[0]); @@ -444,6 +449,20 @@ pub const FilePoll = struct { pub const Set = std.EnumSet(Flags); pub const Struct = std.enums.EnumFieldStruct(Flags, bool, false); + pub const Formatter = std.fmt.Formatter(Flags.format); + + pub fn format(this: Flags.Set, comptime _: []const u8, _: std.fmt.FormatOptions, writer: anytype) !void { + var iter = this.iterator(); + var is_first = true; + while (iter.next()) |flag| { + if (!is_first) { + try writer.print(" | ", .{}); + } + try writer.writeAll(@tagName(flag)); + is_first = false; + } + } + pub fn fromKQueueEvent(kqueue_event: std.os.system.kevent64_s) Flags.Set { var flags = Flags.Set{}; if (kqueue_event.filter == std.os.system.EVFILT_READ) { @@ -551,7 +570,7 @@ pub const FilePoll = struct { } }; - const log = Output.scoped(.FilePoll, false); + const log = bun.sys.syslog; pub inline fn isActive(this: *const FilePoll) bool { return this.flags.contains(.has_incremented_poll_count); diff --git a/src/bun.js/api/bun/process.zig b/src/bun.js/api/bun/process.zig index 0fed6d7165..3b8b31a186 100644 --- a/src/bun.js/api/bun/process.zig +++ b/src/bun.js/api/bun/process.zig @@ -301,11 +301,15 @@ pub const Process = struct { pub fn watch(this: *Process, vm: anytype) JSC.Maybe(void) { _ = vm; // autofix + if (comptime Environment.isWindows) { this.poller.uv.ref(); return JSC.Maybe(void){ .result = {} }; } + if (this.poller != .detached) + return .{ .result = {} }; + if (WaiterThread.shouldUseWaiterThread()) { this.poller = .{ .waiter_thread = .{} }; this.poller.waiter_thread.ref(this.event_loop);