diff options
Diffstat (limited to 'dev/Inbox.zig')
| -rw-r--r-- | dev/Inbox.zig | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/dev/Inbox.zig b/dev/Inbox.zig index 347ad278..d733b971 100644 --- a/dev/Inbox.zig +++ b/dev/Inbox.zig @@ -86,6 +86,11 @@ len: usize = 0, closed: bool = false, files_changed: bool = false, readers: [pardes.MAX_PANES]?u32 = @splat(null), +/// Each pane's reads read out of its pty and not yet applied (`applied`): +/// a command's exit is told only once none is (Ptys.unapplied), since +/// the poll that asks whether its output is in (CommandWatch.due) cannot +/// see a read the reader holds or the queue does. +unapplied: [pardes.MAX_PANES]std.atomic.Value(u32) = @splat(.init(0)), waiting: usize = 0, lsp_id: ?u32 = null, completions: [2 * selection_pipe.Tasks.capacity + 1]Msg = undefined, @@ -110,6 +115,12 @@ pub fn acceptReader(q: *Inbox, pane: pardes.Pane.Id, gen: u32) void { q.readers[pane.index()] = gen; } +/// One of `pane`'s reads applied, or dropped unapplied. +pub fn applied(q: *Inbox, pane: pardes.Pane.Id) void { + const n = &q.unapplied[pane.index()]; + if (n.load(.acquire) > 0) _ = n.fetchSub(1, .acq_rel); +} + pub fn cancelReader(q: *Inbox, pane: pardes.Pane.Id, gen: u32) void { q.lock(); defer q.unlock(); @@ -123,7 +134,10 @@ pub fn cancelReader(q: *Inbox, pane: pardes.Pane.Id, gen: u32) void { .eof => |e| e.pane == pane and e.gen == gen, else => false, }; - if (matches) q.removeAt(i).deinit(q.gpa, q.lsp_allocator) else i += 1; + if (matches) { + if (msg == .output) q.applied(pane); + q.removeAt(i).deinit(q.gpa, q.lsp_allocator); + } else i += 1; } q.space.broadcast(q.io); } @@ -302,11 +316,14 @@ fn readPty(q: *Inbox, pty: std.Io.File, pane: pardes.Pane.Id, gen: u32) void { }, }; if (n == 0) continue; + // Counted at once: out of the pty, the poll no longer sees it. + _ = q.unapplied[pane.index()].fetchAdd(1, .acq_rel); const bytes = q.gpa.dupe(u8, buf[0..n]) catch |err| { + q.applied(pane); failure = err; break; }; - if (!q.pushOutput(pane, gen, bytes)) return; + if (!q.pushOutput(pane, gen, bytes)) return q.applied(pane); } q.push(.{ .eof = .{ .pane = pane, .gen = gen, .failure = failure } }); } |
