From 8d9f4c88072089b53c77ab7e66b01c461fbbee74 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Fri, 20 Nov 2026 04:17:12 -0300 Subject: dev, runtime: the addons' jobs and draws, the pipes and a search answer through the session's one queue in both frontends, and their workers are the queue's: the terminal's own posts to vaxis's queue are deleted (its pipe_done, search_rows and kind_job messages and their arms in apply and in Own.close's drain, deliverSearch, deliverPipe, the two inline deliver functions), its pipe, search, job and draw post with Inbox.pushPipe, pushSearch and pushJob as the window's did and takeQueue lands them; Inbox.land (landLsp grown to every worker's answer: a pipe's, a search's rows, a job's or a draw's, a handover's end) replaces the two frontends' copies of those arms; pipe_tasks and job_tasks leave both Shells and the window's Own for the Inbox beside lsp_task, ended in Inbox.deinit (and so a client's draws in both clients, which the terminal's client never canceled), the pipes canceled by the session loop's Restore and the search's worker by the loop's end, not by each frontend's close and restoring; a terminal client's queue wakes its loop (wakeForQueue) now that its draws come through it; the test first: on the base a search worker's post into vaxis's full queue waited for the loop to take one and a cancel did end it (vaxis's Queue.push waits on a cancelable condition), so no worker could have hung, but the terminal's keys waited behind up to 512 queued batches of rows in that one queue (the input thread's post waits in it too); now rows wait in the session's queue and keys never behind them, pinned by host_io's test of pushSearch into a full queue (a take lets it in, a cancel ends the wait and frees the rows); tui core-test 857/1008 (151 skipped), shell-test 1048/1051, term 17/17, pane 183/184, kitty 45/45, behaviour-test and --replay 275/275, process-test 0 of 144 failed (wheeldrift and exec failed once in the run, passed on their retries), soak --clients 5 diverged 0, unequal 0, checked/wrong 1874/0 1937/0 1831/0, quiet checks 597/0 673/0 779/0, unlisted 0, corpus 22 of 22, no leak; --bytes --clients 5 diverged 0, unequal 0, quiet checks 693/0 586/0 802/0, corpus 22 of 22, no leak, one unlisted stop at `now` at 30 ms (the base's, known); gui unit-test 1645/1649 with only the perf check's BaselineHarnessMismatch; daemon.py plain, --far, --games, --window-clients, --upgrade both ways pass (upgrade-back failed once at its Adopt into the old build's fresh session, then passed 3 of 3) (load 11-22) Co-Authored-By: Claude Opus Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T --- dev/gui/gui.zig | 60 +++++++++------------------------------------------------ 1 file changed, 9 insertions(+), 51 deletions(-) (limited to 'dev/gui/gui.zig') diff --git a/dev/gui/gui.zig b/dev/gui/gui.zig index ab33abe9..fa480665 100644 --- a/dev/gui/gui.zig +++ b/dev/gui/gui.zig @@ -379,7 +379,6 @@ fn sdlWake(_: ?*anyopaque) void { sev.type = c.SDL_EVENT_USER; _ = c.SDL_PushEvent(&sev); } -const PipeTasks = selection_pipe.Tasks; const output_capacity = Queue.output_capacity; const Gui = struct { @@ -991,7 +990,6 @@ const Own = struct { g: *Gui, test_mode: bool, detached: bool, - pipe_tasks: PipeTasks = .{}, shell: Shell = undefined, const Session = session_loop.Loop(Own); @@ -1024,7 +1022,6 @@ const Own = struct { .lsp_allocator = l.allocs.lsp, .ptys = &l.ptys, .queue = &l.inbox, - .pipe_tasks = &o.pipe_tasks, .watches = &l.watches, .fs = l.fs, .test_mode = o.test_mode, @@ -1044,15 +1041,10 @@ const Own = struct { return host; } - pub fn close(o: *Own, l: *Session) void { - const io = l.io; + pub fn close(o: *Own, _: *Session) void { o.shell.fs = null; host_io.setExitWake(null, null); pardes.Kind.drawer = null; - o.shell.job_tasks.cancelAll(io); - o.pipe_tasks.cancelAll(io); - // Its worker may be waiting on the queue for room. - l.core.stream.cancelTask(); o.g.hit_core = null; } @@ -1084,7 +1076,6 @@ const Own = struct { } pub fn restoring(o: *Own, nc: *pardes.Pardes) void { - o.pipe_tasks.cancelAll(o.shell.io); // One view, the window's (host_io.restoreCore). o.shell.gview = 0; o.g.cells.clearImages(); @@ -1415,7 +1406,6 @@ fn clientSession(init: std.process.Init, g: *Gui, opts_in: pardes.Options, test_ var queue: Queue = .{ .io = io, .gpa = gpa, .lsp_allocator = start.allocs.lsp, .wake_fn = sdlWake }; defer queue.deinit(); var ptys: host_io.Ptys = .{ .queue = &queue, .prompt_rcs = undefined }; - var pipe_tasks: PipeTasks = .{}; var no_watches: file_watch.Watches = .{ .io = io, .gpa = gpa, .queue = &queue }; var no_peers: replica.Peers = .{}; var shell: Shell = .{ @@ -1426,7 +1416,6 @@ fn clientSession(init: std.process.Init, g: *Gui, opts_in: pardes.Options, test_ .lsp_allocator = start.allocs.lsp, .ptys = &ptys, .queue = &queue, - .pipe_tasks = &pipe_tasks, .watches = &no_watches, .test_mode = test_mode, .client = &window, @@ -1435,7 +1424,6 @@ fn clientSession(init: std.process.Init, g: *Gui, opts_in: pardes.Options, test_ window.shell = &shell; pardes.Kind.drawer = .{ .ctx = &shell, .go = kindDraw }; defer pardes.Kind.drawer = null; - defer shell.job_tasks.cancelAll(io); g.no_blink = test_mode; defer g.hit_core = null; _ = c.SDL_StartTextInput(g.window); @@ -2351,8 +2339,6 @@ const Shell = struct { queue: *Queue, /// What drainQueue takes each wakeup, kept rather than rebuilt. batch: Queue.Batch = .{}, - pipe_tasks: *PipeTasks, - job_tasks: PipeTasks = .{}, /// The session's file watches (runtime/session.zig's); a client's, /// none. watches: *file_watch.Watches, @@ -2561,10 +2547,7 @@ const Shell = struct { fn takeDraws(s: *Shell) bool { s.queue.takeInto(&s.batch); for (s.batch.slice()) |m| switch (m) { - .kind_job => |j| { - s.job_tasks.finish(s.io, j.id); - j.land(s.core); - }, + .kind_job => s.queue.land(s.core, m), else => m.deinit(s.gpa, s.lsp_allocator), }; return s.batch.slice().len > 0; @@ -2580,33 +2563,10 @@ const Shell = struct { for (msgs.slice()) |m| switch (m) { .output => |o| s.ptys.output(s.core, o), .eof => |e| s.ptys.eof(s.core, e), - .lsp, .lsp_status => s.queue.landLsp(s.core, m), - .pipe => |response_value| { - var response = response_value; - s.core.update(.{ .pipe_resp = .{ - .id = response.id, - .success = response.success, - .outputs = response.outputs, - .failure = response.failure, - } }); - response.deinit(s.gpa); - s.pipe_tasks.finish(s.io, response_value.id); - }, - .search => |b| { - s.core.update(.{ .search = b }); - b.deinit(s.gpa); - }, - .handed => |h| { - s.core.update(.{ .handed = .{ .seq = h.seq, .to = if (h.ok) h.words else "", .failure = if (h.ok) null else h.words } }); - s.gpa.free(h.words); - }, - .kind_job => |j| { - s.job_tasks.finish(s.io, j.id); - j.land(s.core); - }, .files_changed => check_files = true, .fs_ready => {}, .adopted => |a| s.ptys.adoptions.adoptShell(s.core, a.pid, a.fd), + else => s.queue.land(s.core, m), }; if (check_files) s.watches.reload(s.core); } @@ -3178,7 +3138,7 @@ fn lsp(ctx: ?*anyopaque, req: host_io.Lsp.Request) void { fn pipe(ctx: ?*anyopaque, id: u32) void { const s = shellOf(ctx); - if (s.threads_ok) return selection_pipe.start(s.io, s.gpa, s.core, s.pipe_tasks, id, s.queue, Queue.pushPipe); + if (s.threads_ok) return selection_pipe.start(s.io, s.gpa, s.core, &s.queue.pipe_tasks, id, s.queue, Queue.pushPipe); s.core.update(.{ .pipe_resp = .{ .id = id, .success = false, .outputs = &.{} } }); s.core.reportError(.at(s.core.view().active), "pipe", error.WorkersUnavailable); } @@ -3186,13 +3146,13 @@ fn pipe(ctx: ?*anyopaque, id: u32) void { /// A draw (api.draw) on a worker, as a job is. fn kindDraw(ctx: ?*anyopaque, j: *host_io.KindJob) bool { const s = shellOf(ctx); - return (s.threads_ok or s.client != null) and host_io.KindJob.go(s.io, &s.job_tasks, j, s.queue, Queue.pushJob); + return (s.threads_ok or s.client != null) and host_io.KindJob.go(s.io, &s.queue.job_tasks, j, s.queue, Queue.pushJob); } fn kindJob(ctx: ?*anyopaque, id: pardes.Pane.Id, serial: u32, token: u32) void { const pane = id.index(); const s = shellOf(ctx); - if (s.threads_ok) return host_io.KindJob.start(s.io, s.core, &s.job_tasks, pane, serial, token, s.queue, Queue.pushJob); + if (s.threads_ok) return host_io.KindJob.start(s.io, s.core, &s.queue.job_tasks, pane, serial, token, s.queue, Queue.pushJob); host_io.KindJob.runHere(s.core, pane, serial, token); } @@ -5976,7 +5936,6 @@ test "GUI worker setup failures finish matching LSP and pipe requests" { .lsp_allocator = failing.allocator(), }; defer queue.deinit(); - var tasks: PipeTasks = .{}; core.lspRequest(core.view().active, .status, ""); const req: host_io.Lsp.Request = .{ .id = core.lsp_ask.wait.?.id, @@ -6008,11 +5967,11 @@ test "GUI worker setup failures finish matching LSP and pipe requests" { core.update(.{ .key = .{ .cp = 't', .text = "tr a-z A-Z" } }); core.update(.{ .key = .{ .cp = pardes.Key.enter } }); const pipe_id = core.pipe.wait.?.id; - selection_pipe.start(failing_io, failing.allocator(), core, &tasks, pipe_id, &queue, Queue.pushPipe); + selection_pipe.start(failing_io, failing.allocator(), core, &queue.pipe_tasks, pipe_id, &queue, Queue.pushPipe); try std.testing.expect(core.pipe.wait == null); try std.testing.expectEqualStrings("abc", pane.file.?.content); try std.testing.expect(queue.lsp_task == null); - try std.testing.expectEqual(@as(usize, 0), tasks.len); + try std.testing.expectEqual(@as(usize, 0), queue.pipe_tasks.len); try std.testing.expectEqual(@as(usize, 0), queue.len); } } @@ -7676,9 +7635,8 @@ test "a detached GUI authority follows terminal directory changes with no window const rcs: host_io.Shell.PromptFiles = .{}; var ptys: host_io.Ptys = .{ .queue = &queue, .prompt_rcs = &rcs, .gens = @splat(1) }; defer ptys.deinit(); - var pipes: PipeTasks = .{}; var no_peers: replica.Peers = .{}; - var shell: Shell = .{ .core = core, .io = io, .gpa = gpa, .lsp_allocator = gpa, .ptys = &ptys, .queue = &queue, .pipe_tasks = &pipes, .watches = undefined, .peers = &no_peers }; + var shell: Shell = .{ .core = core, .io = io, .gpa = gpa, .lsp_allocator = gpa, .ptys = &ptys, .queue = &queue, .watches = undefined, .peers = &no_peers }; const child = try host_io.forkShell(null, 0, &rcs, "/bin/sh", start, 24, 80); ptys.slots[0] = .{ .fd = child.file.handle, .pid = child.pid }; try std.testing.expect(host_io.writeFd(child.file.handle, "cd child\n")); -- cgit v1.3 From 26d0581168ac4b582025ecb01b36968850344811 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Fri, 20 Nov 2026 06:07:10 -0300 Subject: runtime, dev: the daemon's notes are the session loop's own, so `note` leaves the frontend calls (nine to eight: options, open, close, start, sent, upgradeAsked, restoring, restored): the loop's note puts an adopted shell on its queue (both frontends take it in their wait), hands a client's connection to Peers (joined at the next step boundary, its post the wake, as the window did) and wakes the queue for a new daemon's hello; the terminal's deliverNote, its adopted and replica messages and arms (in apply and in Own.close's drain) and the window's deliverNote and both Own.note are deleted, the terminal's Shell names its session loop (`session`) so that a quit before the first frame starts the daemon's reader through the loop's watch; and the test first: an Adopt's shells arriving while output fills the queue were dropped by Inbox.push, their masters closed and the shells lost with them (448 outputs in, the shell and the end of the list pushed, 448 taken), in the window today, and in the terminal once its notes came through this queue (vaxis's queue had made the daemon's thread wait); the queue now keeps room for one Adopt's shells beyond the output's (adopt_capacity, the ring 64 + 1 longer, the output's bound unchanged) and each pane's end of file beyond those; a user could have hit it: Adopt in a window while another pane floods; tui core-test 858/1009 (151 skipped), shell-test 1049/1052, term 17/17, pane 183/184, kitty 45/45, behaviour-test and --replay 275/275, process-test 0 of 144 failed (msg, pagercolor and exec-bigdrag failed once in the run, passed on their retries), soak --clients 5 diverged 0, unequal 0, checked/wrong 1874/0 1937/0 1831/0, quiet checks 597/0 673/0 779/0, unlisted 0, corpus 22 of 22, no leak; --bytes --clients 5 diverged 0, unequal 0, quiet checks 693/0 586/0 802/0, corpus 22 of 22, no leak, its one unlisted stop at `now` the base's; gui unit-test 1646/1650 with only BaselineHarnessMismatch; daemon.py plain, --far, --games (keys stopped 0 and 0), --window-clients, --upgrade both ways pass (load 8-22) Co-Authored-By: Claude Opus Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T --- dev/Inbox.zig | 10 +++++++--- dev/gui/gui.zig | 19 ------------------- dev/host_io.zig | 21 ++++++++++++++++++++- dev/tui/tui.zig | 47 ++++++++++------------------------------------- runtime/session.zig | 21 +++++++++++++++------ test/replicas.zig | 1 - 6 files changed, 52 insertions(+), 67 deletions(-) (limited to 'dev/gui/gui.zig') 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), } } diff --git a/runtime/session.zig b/runtime/session.zig index e425fa3f..64846319 100644 --- a/runtime/session.zig +++ b/runtime/session.zig @@ -25,8 +25,6 @@ //! session's first wait (`l.watch`). //! - `sent()`: after each step's unit went to the clients. //! - `upgradeAsked()`: an Upgrade asked in the step, done (it execs). -//! - `note(n)`: what the daemon says (an adopted shell, a client's -//! connection, a new daemon's hello taken), onto its queue. //! - `restoring(nc)`, `restored(l)`: a Restore's new core, before it //! replaces the old one (its devices let go, what it is told of the //! frontend) and after (its own view of it again). @@ -145,17 +143,28 @@ pub fn Loop(comptime Frontend: type) type { while (l.core.nextEffect()) |e| l.core.perform(e); } - /// What the daemon says, onto the frontend's queue (once: its + /// What the daemon says, onto the session's queue (once: its /// reader is started by the first call); and a daemon started /// since the last one died told the shells' masters it held. pub fn watch(l: *L) void { if (daemon.relinked()) l.ptys.tellDaemon(); - daemon.watch(l.fe, note); + daemon.watch(l, note); } + /// The daemon's thread: an adopted shell onto the queue (taken + /// in the frontend's wait), a client's connection to `Peers` + /// (joined at the next step boundary), a new daemon's hello taken + /// a wake (`watch` tells it the rest). fn note(ctx: *anyopaque, n: daemon.Note) void { - const fe: *Frontend = @ptrCast(@alignCast(ctx)); - fe.note(n); + const l: *L = @ptrCast(@alignCast(ctx)); + switch (n) { + .relinked => l.inbox.wake(), + .adopted => |a| { + for (a.pids[0..a.n], a.fds[0..a.n]) |pid, fd| l.inbox.push(.{ .adopted = .{ .pid = pid, .fd = fd } }); + l.inbox.push(.{ .adopted = .{ .pid = 0, .fd = -1 } }); + }, + .replica => |j| l.peers.handed(j.fd, j.view), + } } /// A Restore: the core its dump makes replaces this one, its clients diff --git a/test/replicas.zig b/test/replicas.zig index 7bf79055..7610ad8c 100644 --- a/test/replicas.zig +++ b/test/replicas.zig @@ -1120,7 +1120,6 @@ const Soak = struct { } pub fn upgradeAsked(_: *Soak) void {} - pub fn note(_: *Soak, _: anytype) void {} pub fn restoring(_: *Soak, _: *pardes.Pardes) void {} pub fn restored(_: *Soak, _: *SessionLoop) void {} -- cgit v1.3