summaryrefslogtreecommitdiff
path: root/runtime/session.zig
diff options
context:
space:
mode:
Diffstat (limited to 'runtime/session.zig')
-rw-r--r--runtime/session.zig37
1 files changed, 26 insertions, 11 deletions
diff --git a/runtime/session.zig b/runtime/session.zig
index 0bd38c86..9c8446e3 100644
--- a/runtime/session.zig
+++ b/runtime/session.zig
@@ -6,10 +6,10 @@
//! posts, `Inbox`), its ptys (`Ptys`) and the files it watches
//! (`file_watch.Watches`): a step, its unit to the clients and theirs
//! taken in, an Upgrade or a Restore between steps; and the order its
-//! parts end in. Its other devices (the LSP's and the pipes' and addons'
-//! jobs, the session's own input) are still its frontend's (each `Shell`);
-//! the language servers' answers come through its queue (`Inbox.startLsp`).
-//! What a frontend does is:
+//! parts end in. Its workers (a language server's query, the pipes, the
+//! addons' jobs and draws, a search) answer through its queue, which holds
+//! their tasks and ends them (`Inbox.land`, `Inbox.deinit`); the session's
+//! own input is its frontend's (each `Shell`). What a frontend does is:
//!
//! - `options(o)`: before the core: what it gives the core it starts (a
//! window's size, for a dump's layout).
@@ -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).
@@ -75,6 +73,7 @@ pub fn Loop(comptime Frontend: type) type {
o.tree_sitter_allocator = l.allocs.tree_sitter;
o.frame_allocator = l.allocs.frame;
fe.options(&o);
+ o.tape = pardes.tape.fromEnv();
l.core = if (upgrade.resumed) |*rec|
try upgrade.load(l.gpa, l.allocs.pardes, o, rec)
else if (o.load_path) |lp| blk: {
@@ -90,6 +89,8 @@ pub fn Loop(comptime Frontend: type) type {
l.peers = .{ .gpa = l.gpa, .io = l.io, .name = daemon.name() };
l.inbox = .{ .io = l.io, .gpa = l.gpa, .lsp_allocator = l.allocs.lsp };
defer l.inbox.deinit();
+ // A search's worker may be waiting on the queue for room.
+ defer l.core.stream.cancelTask();
// The language servers' status lines, from the first effects on.
pardes.lsp.setStatusSink(&l.inbox, host_io.Inbox.lspStatus);
defer pardes.lsp.setStatusSink(null, null);
@@ -100,6 +101,7 @@ pub fn Loop(comptime Frontend: type) type {
l.host = try fe.open(&l);
defer fe.close(&l);
+ daemon.notesTo(&l, note);
defer l.peers.deinit();
// Before the core goes: each client sees its link end.
defer l.peers.dropAll(l.core);
@@ -156,17 +158,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();
}
+ /// 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
@@ -175,7 +188,9 @@ pub fn Loop(comptime Frontend: type) type {
fn restore(l: *L, path: []const u8) void {
const nc = host_io.restoreCore(l.gpa, l.core, path, &l.peers, l.watches.fd, &l.watches.table) orelse return;
l.fe.restoring(nc);
- // An answer to the old core's query is turned away.
+ // The old core's pipes end, and an answer to its query is
+ // turned away.
+ l.inbox.pipe_tasks.cancelAll(l.io);
l.inbox.discardCompletions();
l.ptys.stop();
nc.host = l.host;