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/Inbox.zig | 44 +++++++++++++++++++++---- dev/gui/gui.zig | 60 ++++++---------------------------- dev/host_io.zig | 32 +++++++++++++++++++ dev/tui/tui.zig | 99 ++++++++++++++------------------------------------------- 4 files changed, 102 insertions(+), 133 deletions(-) (limited to 'dev') diff --git a/dev/Inbox.zig b/dev/Inbox.zig index aac1f7a1..234d89eb 100644 --- a/dev/Inbox.zig +++ b/dev/Inbox.zig @@ -63,6 +63,11 @@ gpa: std.mem.Allocator, lsp_allocator: std.mem.Allocator, /// The query in flight; the UI thread's alone (spawnLsp, teardown). lsp_task: ?Lsp.Task = null, +/// The `|` pipes' and the addons' jobs' and draws' workers in flight, each +/// posting its answer here (`pushPipe`, `pushJob`); the loop's thread's +/// alone: joined as their answers land (`land`), canceled at the end. +pipe_tasks: selection_pipe.Tasks = .{}, +job_tasks: selection_pipe.Tasks = .{}, /// Wakes the host's loop after a push from another thread: an SDL /// event, a macOS runtime callback. Null: nobody to wake (tests). wake_fn: ?*const fn (?*anyopaque) void = null, @@ -262,9 +267,11 @@ pub fn close(q: *Inbox) void { } pub fn deinit(q: *Inbox) void { - // The query in flight ends first: what it still delivers is dropped. + // The workers in flight end first: what they still deliver is dropped. if (q.lsp_task) |*t| t.future.cancel(q.io); q.lsp_task = null; + q.pipe_tasks.cancelAll(q.io); + q.job_tasks.cancelAll(q.io); q.close(); std.debug.assert(q.waiting == 0); } @@ -311,9 +318,10 @@ pub fn startLsp(q: *Inbox, core: *pardes.Pardes, e: Lsp.Request) void { Lsp.start(q.io, q.lsp_allocator, core, &q.lsp_task, e, q, pushLspRows); } -/// A language server's answer or status line taken off the queue, to the -/// core (whichever frontend took it). -pub fn landLsp(q: *Inbox, core: *pardes.Pardes, m: Msg) void { +/// A worker's answer taken off the queue, to the core (whichever frontend +/// took it), its worker joined: a language server's answer or status line, +/// a pipe's, a search's rows, an addon's job or draw, a handover's end. +pub fn land(q: *Inbox, core: *pardes.Pardes, m: Msg) void { switch (m) { .lsp => |l| { core.update(.{ .lsp_resp = .{ .id = l.id, .rows = l.rows } }); @@ -324,7 +332,30 @@ pub fn landLsp(q: *Inbox, core: *pardes.Pardes, m: Msg) void { core.setStatus(.at(core.view().active), pardes.Messages.Message.stamp(&mbuf, "lsp", text)); q.lsp_allocator.free(text); }, - else => unreachable, + .pipe => |response_value| { + var response = response_value; + core.update(.{ .pipe_resp = .{ + .id = response.id, + .success = response.success, + .outputs = response.outputs, + .failure = response.failure, + } }); + response.deinit(q.gpa); + q.pipe_tasks.finish(q.io, response_value.id); + }, + .search => |b| { + core.update(.{ .search = b }); + b.deinit(q.gpa); + }, + .kind_job => |j| { + q.job_tasks.finish(q.io, j.id); + j.land(core); + }, + .handed => |h| { + core.update(.{ .handed = .{ .seq = h.seq, .to = if (h.ok) h.words else "", .failure = if (h.ok) null else h.words } }); + q.gpa.free(h.words); + }, + .output, .eof, .files_changed, .fs_ready, .adopted => unreachable, } } @@ -340,12 +371,13 @@ pub fn lspStatus(ctx: ?*anyopaque, text: []const u8) void { q.push(.{ .lsp_status = copy }); } -/// A `|` job's answer (selection_pipe.start's sink). +/// An addon's job or draw done (KindJob.go's sink). pub fn pushJob(ctx: ?*anyopaque, j: *KindJob) void { const q: *Inbox = @ptrCast(@alignCast(ctx.?)); q.push(.{ .kind_job = j }); } +/// A `|` pipe's answer (selection_pipe.start's sink). pub fn pushPipe(ctx: ?*anyopaque, response: selection_pipe.Response) void { const q: *Inbox = @ptrCast(@alignCast(ctx.?)); q.push(.{ .pipe = response }); 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")); diff --git a/dev/host_io.zig b/dev/host_io.zig index 5465fc7a..1c4fe332 100644 --- a/dev/host_io.zig +++ b/dev/host_io.zig @@ -2270,6 +2270,38 @@ test "PTY EOF reserve cannot evict terminal output" { for (batch.items[Inbox.output_capacity..batch.len], 0..) |msg, pane| try std.testing.expectEqual(pane, msg.eof.pane.index()); } +test "a search's rows posted into a full queue wait for room: a take lets them in, a cancel ends the wait and frees them" { + const gpa = std.testing.allocator; + const io = std.testing.io; + var queue: Inbox = .{ .io = io, .gpa = gpa, .lsp_allocator = gpa }; + defer queue.deinit(); + queue.acceptReader(.at(0), 1); + const Post = struct { + fn run(q: *Inbox, posted: *?bool) void { + const rows = std.testing.allocator.dupe(u8, "a.txt:1:1-2 hit\n") catch return; + posted.* = Inbox.pushSearch(q, .{ .gen = 1, .rows = rows }); + } + }; + for ([_]bool{ false, true }) |cancel| { + // The loop busy: its queue full of output. + for (0..Inbox.output_capacity) |_| queue.push(.{ .output = .{ .pane = .at(0), .gen = 1, .bytes = try gpa.dupe(u8, "busy") } }); + var posted: ?bool = null; + var worker = try io.concurrent(Post.run, .{ &queue, &posted }); + try PtyTests.waitBlocked(&queue); + if (cancel) worker.cancel(io) else { + var batch = queue.take(); + for (batch.slice()) |msg| msg.deinit(gpa, gpa); + worker.await(io); + } + try std.testing.expectEqual(!cancel, posted.?); + var rest = queue.take(); + defer for (rest.slice()) |msg| msg.deinit(gpa, gpa); + try std.testing.expectEqual(@as(usize, if (cancel) Inbox.output_capacity else 1), rest.len); + if (!cancel) try std.testing.expectEqualStrings("a.txt:1:1-2 hit\n", rest.items[0].search.rows); + try std.testing.expectEqual(@as(usize, 0), queue.waiting); + } +} + 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 543be3aa..1b00d1b9 100644 --- a/dev/tui/tui.zig +++ b/dev/tui/tui.zig @@ -97,8 +97,9 @@ fn kittyShmProbe(w: *std.Io.Writer, feed: *Feed) void { w.flush() catch {}; } -/// What the loop's queue carries: a terminal's input, a pane's output, a -/// worker's answer, a wake. +/// 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`). const Msg = union(enum) { nop, /// The terminal's input ended: its end of file, a hangup. A session @@ -120,11 +121,6 @@ const Msg = union(enum) { paste: []const u8, paste_start, paste_end, - pipe_done: selection_pipe.Response, - /// A streaming search's rows (pardes.Stream). - search_rows: pardes.Stream.Batch, - /// A kind's job done on a worker (host_io.KindJob). - kind_job: *host_io.KindJob, fs_ready, /// A replica's connection, handed over by the daemon (Peers). replica: daemon.Joining, @@ -369,8 +365,6 @@ const TestReader = struct { } }; -const PipeTasks = selection_pipe.Tasks; - /// A watched child exited: wake the loop, which takes it (`takeExits`). fn wakeForExit(ctx: ?*anyopaque) void { const loop: *Loop = @ptrCast(@alignCast(ctx.?)); @@ -760,7 +754,7 @@ pub fn runClient(init: std.process.Init, opts: pardes.Options, path: []const u8, var c = try Client.init(&tty, &start); defer c.link.deinit(gpa); // A client has no clients of its own, and spawns nothing: its pty - // table an empty one over an empty queue. + // table an empty one over a queue that carries its draws alone. var no_peers: replica.Peers = .{}; var no_inbox: host_io.Inbox = .{ .io = io, .gpa = gpa, .lsp_allocator = start.allocs.lsp }; defer no_inbox.deinit(); @@ -783,6 +777,8 @@ pub fn runClient(init: std.process.Init, opts: pardes.Options, path: []const u8, .ptys = &no_ptys, }; tty = .{ .sh = &sh, .screen = &screen, .loop = &loop, .joins = &start }; + no_inbox.wake_fn = Shell.wakeForQueue; + no_inbox.wake_ctx = &sh; pardes.Kind.drawer = .{ .ctx = &sh, .go = Shell.draw }; defer pardes.Kind.drawer = null; @@ -985,18 +981,8 @@ const Own = struct { stopInput(io, &o.screen.thread); pardes.Kind.drawer = null; host_io.setExitWake(null, null); - sh.pipe_tasks.cancelAll(io); - sh.job_tasks.cancelAll(io); - // Its worker may be waiting on the loop's queue for room. - sh.core.stream.cancelTask(); while (loop.tryEvent() catch null) |ev| switch (ev) { .paste => |b| gpa.free(@constCast(b)), - .pipe_done => |response_value| { - var response = response_value; - response.deinit(gpa); - }, - .search_rows => |b| b.deinit(gpa), - .kind_job => |j| j.drop(), .adopted => |a| _ = libc.close(a.fd), else => {}, }; @@ -1040,7 +1026,6 @@ const Own = struct { pub fn restoring(o: *Own, nc: *pardes.Pardes) void { const sh = &o.sh; const io = sh.io; - sh.pipe_tasks.cancelAll(io); // One view, the terminal's (host_io.restoreCore). const live = o.screen; stopInput(io, &live.thread); @@ -1124,8 +1109,6 @@ const Shell = struct { batch: host_io.Inbox.Batch = .{}, batch_at: usize = 0, queue_woken: std.atomic.Value(bool) = .init(false), - pipe_tasks: PipeTasks = .{}, - job_tasks: PipeTasks = .{}, threads_ok: bool = false, check_files: bool = false, in_paste: bool = false, @@ -1648,27 +1631,6 @@ const Shell = struct { s.paste_buf.clearRetainingCapacity(); }, .fs_ready => {}, - .pipe_done => |response_value| { - var response = response_value; - 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_rows => |b| { - core.update(.{ .search = b }); - b.deinit(s.gpa); - }, - .kind_job => |j| { - s.job_tasks.finish(s.io, j.id); - j.land(core); - // A client's draw done: its frame is its own to draw again. - if (s.client) |cl| cl.link.dirty = true; - }, } return false; } @@ -1877,7 +1839,8 @@ const Shell = struct { } /// What the session's queue holds: its ptys' output (`waitInput` - /// paces it; the focused pane's is its echo) and their ends of file. + /// paces it; the focused pane's is its echo), their ends of file and + /// the workers' answers. /// A read a step, as the terminal's own queue gave them: the frame /// after one shows it before what came after it (a command's last line /// before its exit scrolls it away), the rest kept for the next wait. @@ -1905,8 +1868,13 @@ const Shell = struct { }, .eof => |e| s.ptys.eof(s.core, e), .files_changed => s.check_files = true, - .lsp, .lsp_status => s.ptys.queue.landLsp(s.core, m), - else => m.deinit(s.gpa, s.lsp_gpa), + .kind_job => { + s.ptys.queue.land(s.core, m); + // 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), + else => s.ptys.queue.land(s.core, m), } } } @@ -1961,50 +1929,29 @@ const Shell = struct { s.core.update(.{ .pipe_resp = .{ .id = id, .success = false, .outputs = &.{} } }); return s.core.reportError(.at(s.core.view().active), "pipe", error.WorkersUnavailable); } - selection_pipe.start(s.io, s.gpa, s.core, &s.pipe_tasks, id, s, deliverPipe); + const q = s.ptys.queue; + selection_pipe.start(s.io, s.gpa, s.core, &q.pipe_tasks, id, q, host_io.Inbox.pushPipe); } fn search(ctx: ?*anyopaque, gen: u32) void { const s = of(ctx); - if (s.threads_ok) return pardes.Stream.start(s.io, s.gpa, s.core, gen, s, deliverSearch); + if (s.threads_ok) return pardes.Stream.start(s.io, s.gpa, s.core, gen, s.ptys.queue, host_io.Inbox.pushSearch); pardes.Stream.runHere(s.core, gen, true); } /// A draw (api.draw) on a worker, as a job is. fn draw(ctx: ?*anyopaque, j: *host_io.KindJob) bool { const s = of(ctx); - return (s.threads_ok or s.client != null) and host_io.KindJob.go(s.io, &s.job_tasks, j, s, struct { - fn deliver(c: ?*anyopaque, k: *host_io.KindJob) void { - of(c).loop.postEvent(.{ .kind_job = k }) catch k.drop(); - } - }.deliver); + const q = s.ptys.queue; + return (s.threads_ok or s.client != null) and host_io.KindJob.go(s.io, &q.job_tasks, j, q, host_io.Inbox.pushJob); } fn job(ctx: ?*anyopaque, id: pardes.Pane.Id, serial: u32, token: u32) void { const pane = id.index(); const s = of(ctx); if (!s.threads_ok) return host_io.KindJob.runHere(s.core, pane, serial, token); - host_io.KindJob.start(s.io, s.core, &s.job_tasks, pane, serial, token, s, struct { - fn deliver(c: ?*anyopaque, j: *host_io.KindJob) void { - of(c).loop.postEvent(.{ .kind_job = j }) catch j.drop(); - } - }.deliver); - } - - /// The loop's queue waits for room (a wait the worker's cancel ends). - fn deliverSearch(ctx: ?*anyopaque, batch: pardes.Stream.Batch) bool { - const s = of(ctx); - s.loop.postEvent(.{ .search_rows = batch }) catch { - batch.deinit(s.gpa); - return false; - }; - return true; - } - - fn deliverPipe(ctx: ?*anyopaque, response: selection_pipe.Response) void { - const s = of(ctx); - var owned = response; - s.loop.postEvent(.{ .pipe_done = owned }) catch owned.deinit(s.gpa); + const q = s.ptys.queue; + host_io.KindJob.start(s.io, s.core, &q.job_tasks, pane, serial, token, q, host_io.Inbox.pushJob); } }; @@ -2737,7 +2684,7 @@ test "TTY worker setup failures finish matching LSP and pipe requests" { 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), shell.pipe_tasks.len); + try std.testing.expectEqual(@as(usize, 0), queue.pipe_tasks.len); } } -- cgit v1.3