diff options
Diffstat (limited to 'dev')
| -rw-r--r-- | dev/Inbox.zig | 10 | ||||
| -rw-r--r-- | dev/gui/gui.zig | 19 | ||||
| -rw-r--r-- | dev/host_io.zig | 21 | ||||
| -rw-r--r-- | dev/tui/tui.zig | 47 |
4 files changed, 37 insertions, 60 deletions
diff --git a/dev/Inbox.zig b/dev/Inbox.zig index 234d89eb..347ad278 100644 --- a/dev/Inbox.zig +++ b/dev/Inbox.zig @@ -47,8 +47,12 @@ pub const Msg = union(enum) { } }; -pub const capacity = 512; -pub const output_capacity = capacity - pardes.MAX_PANES; +/// The ring's room: output up to `output_capacity` (a reader waits for +/// more), an Adopt's shells beyond it (one note's: never lost to a flood), +/// and each pane's end of file beyond those (lost to neither). +pub const output_capacity = 512 - pardes.MAX_PANES; +const adopt_capacity = output_capacity + pardes.MAX_PANES + 1; +pub const capacity = adopt_capacity + pardes.MAX_PANES; pub const Batch = struct { items: [capacity + 2 * selection_pipe.Tasks.capacity + 2]Msg = undefined, @@ -194,7 +198,7 @@ pub fn push(q: *Inbox, m: Msg) void { return; } std.debug.assert(q.len < q.items.len); - } else if (q.len >= output_capacity) { + } else if (q.len >= @as(usize, if (m == .adopted) adopt_capacity else output_capacity)) { q.unlock(); m.deinit(q.gpa, q.lsp_allocator); return; diff --git a/dev/gui/gui.zig b/dev/gui/gui.zig index fa480665..72ad1eed 100644 --- a/dev/gui/gui.zig +++ b/dev/gui/gui.zig @@ -1071,10 +1071,6 @@ const Own = struct { if (o.shell.upgrade_asked) |pane| o.shell.upgradeNow(pane); } - pub fn note(o: *Own, n: daemon.Note) void { - deliverNote(&o.shell, n); - } - pub fn restoring(o: *Own, nc: *pardes.Pardes) void { // One view, the window's (host_io.restoreCore). o.shell.gview = 0; @@ -3073,21 +3069,6 @@ fn guiNow(ctx: ?*anyopaque) u64 { return s.test_clock orelse s.paced_ns orelse c.SDL_GetTicksNS(); } -/// The daemon's thread: what it says, onto the queue (drainQueue). -fn deliverNote(ctx: *anyopaque, note: daemon.Note) void { - const s: *Shell = @ptrCast(@alignCast(ctx)); - const q = s.queue; - switch (note) { - .relinked => q.wake(), - .adopted => |a| { - for (a.pids[0..a.n], a.fds[0..a.n]) |pid, fd| q.push(.{ .adopted = .{ .pid = pid, .fd = fd } }); - q.push(.{ .adopted = .{ .pid = 0, .fd = -1 } }); - }, - // Joined at the next step boundary (Peers, any thread). - .replica => |j| s.peers.handed(j.fd, j.view), - } -} - fn writeDump(ctx: ?*anyopaque, bytes: []const u8) void { host_io.writeDump(shellOf(ctx).core, bytes); } diff --git a/dev/host_io.zig b/dev/host_io.zig index 1c4fe332..0efb37fd 100644 --- a/dev/host_io.zig +++ b/dev/host_io.zig @@ -2265,7 +2265,7 @@ test "PTY EOF reserve cannot evict terminal output" { for (0..pardes.MAX_PANES) |pane| queue.push(.{ .eof = .{ .pane = .at(pane), .gen = 1 } }); var batch = queue.take(); defer for (batch.slice()) |msg| msg.deinit(gpa, gpa); - try std.testing.expectEqual(Inbox.capacity, batch.len); + try std.testing.expectEqual(Inbox.output_capacity + pardes.MAX_PANES, batch.len); for (batch.items[0..Inbox.output_capacity]) |msg| try std.testing.expectEqualStrings("before", msg.output.bytes); for (batch.items[Inbox.output_capacity..batch.len], 0..) |msg, pane| try std.testing.expectEqual(pane, msg.eof.pane.index()); } @@ -2302,6 +2302,25 @@ test "a search's rows posted into a full queue wait for room: a take lets them i } } +test "an Adopt's shells are taken in whatever output fills the queue" { + const gpa = std.testing.allocator; + var queue: Inbox = .{ .io = std.testing.io, .gpa = gpa, .lsp_allocator = gpa }; + defer queue.deinit(); + queue.acceptReader(.at(0), 1); + for (0..Inbox.output_capacity) |_| queue.push(.{ .output = .{ .pane = .at(0), .gen = 1, .bytes = try gpa.dupe(u8, "flood") } }); + var fds: [2]c_int = undefined; + if (libc.pipe(&fds) != 0) return error.PipeFailed; + defer _ = libc.close(fds[1]); + queue.push(.{ .adopted = .{ .pid = 42, .fd = fds[0] } }); + queue.push(.{ .adopted = .{ .pid = 0, .fd = -1 } }); + var batch = queue.take(); + defer for (batch.slice()) |msg| msg.deinit(gpa, gpa); + try std.testing.expectEqual(Inbox.output_capacity + 2, batch.len); + try std.testing.expectEqual(@as(libc.pid_t, 42), batch.items[Inbox.output_capacity].adopted.pid); + try std.testing.expectEqual(fds[0], batch.items[Inbox.output_capacity].adopted.fd); + try std.testing.expectEqual(@as(libc.pid_t, 0), batch.items[Inbox.output_capacity + 1].adopted.pid); +} + test "completions retain their arrival order across LSP and pipes" { const gpa = std.testing.allocator; var queue: Inbox = .{ .io = std.testing.io, .gpa = gpa, .lsp_allocator = gpa, .lsp_id = 2 }; diff --git a/dev/tui/tui.zig b/dev/tui/tui.zig index 1b00d1b9..ecc52df0 100644 --- a/dev/tui/tui.zig +++ b/dev/tui/tui.zig @@ -97,16 +97,14 @@ fn kittyShmProbe(w: *std.Io.Writer, feed: *Feed) void { w.flush() catch {}; } -/// What the loop's queue carries: a terminal's input, a wake, what the -/// daemon and a replica's reader hand over. A pane's output and a worker's -/// answer are the session's queue's (Inbox, `takeQueue`). +/// What the loop's queue carries: a terminal's input, a wake, what a +/// replica client's reader hands over. A pane's output, a worker's answer +/// and the daemon's notes are the session's queue's (Inbox, `takeQueue`). const Msg = union(enum) { nop, /// The terminal's input ended: its end of file, a hangup. A session /// a daemon keeps carries on detached; any other ends. quit, - /// A shell a dead session left, its pty's master (daemon.Note.adopted). - adopted: struct { pid: posix.pid_t, fd: posix.fd_t }, /// A timed wait ran out: the core's next wake has come. wake, /// A SIGWINCH: a terminal changed size (Shell.winched). @@ -122,8 +120,6 @@ const Msg = union(enum) { paste_start, paste_end, fs_ready, - /// A replica's connection, handed over by the daemon (Peers). - replica: daemon.Joining, /// A replica's reader posted: the step boundary takes it in. replica_mail, /// A replica client's: what the session streamed (replica.Link). @@ -953,6 +949,7 @@ const Own = struct { .test_clock = host_io.testClock(), .peers = &l.peers, .ptys = &l.ptys, + .session = l, }; const sh = &o.sh; sh.screen = o.screen; @@ -983,7 +980,6 @@ const Own = struct { host_io.setExitWake(null, null); while (loop.tryEvent() catch null) |ev| switch (ev) { .paste => |b| gpa.free(@constCast(b)), - .adopted => |a| _ = libc.close(a.fd), else => {}, }; o.screen.art.deinit(gpa); @@ -1019,10 +1015,6 @@ const Own = struct { if (o.sh.upgrade_asked) |pane| o.sh.upgradeNow(pane); } - pub fn note(o: *Own, n: daemon.Note) void { - deliverNote(o.loop, n); - } - pub fn restoring(o: *Own, nc: *pardes.Pardes) void { const sh = &o.sh; const io = sh.io; @@ -1054,24 +1046,6 @@ fn clearNativeImages( kitty_handles.clearRetainingCapacity(); } -/// The daemon's thread: what it says, onto the loop's queue. -fn deliverNote(ctx: *anyopaque, note: daemon.Note) void { - const loop: *Loop = @ptrCast(@alignCast(ctx)); - switch (note) { - // A full queue wakes it anyway. - .relinked => _ = loop.tryPostEvent(.nop) catch false, - .adopted => |a| { - for (a.pids[0..a.n], a.fds[0..a.n]) |pid, fd| loop.postEvent(.{ .adopted = .{ .pid = pid, .fd = fd } }) catch { - _ = libc.close(fd); - }; - loop.postEvent(.{ .adopted = .{ .pid = 0, .fd = -1 } }) catch {}; - }, - .replica => |j| loop.postEvent(.{ .replica = j }) catch { - _ = libc.close(j.fd); - }, - } -} - /// A replica reader's post: the session's wait ends, and its step /// boundary takes the post in. fn wakeForReplica(ctx: ?*anyopaque) void { @@ -1103,6 +1077,9 @@ const Shell = struct { /// The session's ptys (runtime/session.zig's); a client's, an empty /// table over an empty queue. ptys: *host_io.Ptys, + /// The session's loop (its `watch`, the daemon's notes); a client's + /// and a test's, none. + session: ?*Own.Session = null, /// What `takeQueue` takes off the ptys' queue, and whether the loop /// was woken for it since it last did (one wake, not one a read ahead /// of the terminal's keys in the loop's queue). @@ -1563,7 +1540,7 @@ const Shell = struct { // without it, to be attached again. Gone before the first // frame, the reader that takes the daemon's `ok` (kept // waits on it) is not started yet: started here. - daemon.watch(s.loop, deliverNote); + if (s.session) |l| l.watch(); if (daemon.kept()) { if (!s.detached()) s.leaveTerminal(); return true; @@ -1571,11 +1548,6 @@ const Shell = struct { core.quit = true; return true; }, - .adopted => |a| s.ptys.adoptions.adoptShell(s.core, a.pid, a.fd), - .replica => |j| { - s.peers.handed(j.fd, j.view); - s.input_seen = true; - }, .replica_mail => if (s.peers.urgent.swap(false, .acq_rel)) { s.input_seen = true; }, @@ -1873,7 +1845,8 @@ const Shell = struct { // A client's draw done: its frame is its own to draw again. if (s.client) |cl| cl.link.dirty = true; }, - .fs_ready, .adopted => m.deinit(s.gpa, s.lsp_gpa), + .adopted => |a| s.ptys.adoptions.adoptShell(s.core, a.pid, a.fd), + .fs_ready => {}, else => s.ptys.queue.land(s.core, m), } } |
