summaryrefslogtreecommitdiff
path: root/src/replica.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/replica.zig')
-rw-r--r--src/replica.zig33
1 files changed, 16 insertions, 17 deletions
diff --git a/src/replica.zig b/src/replica.zig
index cac8ed59..a96a056a 100644
--- a/src/replica.zig
+++ b/src/replica.zig
@@ -222,14 +222,18 @@ pub const Authority = struct {
//
// A message of either side is u8 pane, u32 the pane's serial (a slot's
// next pane is another), u8 kind, and the kind's bytes:
-// to a replica: kind 1, a delta; kind 2, rows it asked for (encodeRows);
+// to a replica: kind 1, a delta; kind 2, rows (encodeRows): asked for,
+// or a step read them;
// to the authority: kind 1, an acknowledgement (u32 seq); kind 2, a
// request for rows (u64 lo, u64 hi, absolute); kind 3, a
// delta refused: start this terminal afresh.
-// The authority sends a peer what it is owed (`Screens.flush`) before it
-// steps any input but a pty's output, and once a frame; a replica takes
-// them in that order between units (`Replica.screen`). So a step a replica
-// replays reads the terminal its authority's read.
+// In the authority's stream to a peer, before it steps any input but a
+// pty's output, and once a frame: its own steps since the last unit, as one
+// (`Authority.pending`), then what the peer is owed of the terminals
+// (`Screens.flush`). After a step, before its unit: the rows it read that
+// the peer holds as holes (`Screens.fill`, then `filled`). A replica takes
+// them in that order between units (`Replica.screen`), so a step it replays
+// reads the terminal its authority's step read.
const kind_delta = 1;
const kind_rows = 2;
@@ -490,7 +494,7 @@ pub const Replica = struct {
}
pub fn deinit(r: *Replica) void {
- for (&r.screens) |*slot| if (slot.*) |*sc| sc.rep.deinit(r.coreGpa());
+ for (&r.screens) |*slot| if (slot.*) |*sc| sc.rep.deinit(terminal.emulator_gpa);
if (r.t.core) |c| {
const was = Stepping.begin(&r.t, &r.epoch);
if (r.copy.held) r.copy.restore();
@@ -718,10 +722,6 @@ pub const Replica = struct {
return r.pending.items.len == 0 and r.applied == 0 and !r.copy.held;
}
- fn coreGpa(r: *Replica) Allocator {
- return r.epoch.allocator();
- }
-
/// One of the authority's terminal messages (`Screens.flush`, or an
/// answer to `screenRequests`), taken between units in stream order: a
/// delta written into its pane's emulator, or fetched rows. The
@@ -735,18 +735,17 @@ pub const Replica = struct {
const state = pane.terminal orelse return null;
const slot = &r.screens[m.pane];
if (slot.* == null or slot.*.?.serial != m.serial) {
- if (slot.*) |*old| old.rep.deinit(r.coreGpa());
+ if (slot.*) |*old| old.rep.deinit(terminal.emulator_gpa);
slot.* = .{ .serial = m.serial };
}
const sc = &slot.*.?;
- // The emulator is the authority's, outside every rollback copy:
- // what it allocates now must outlive one.
- const was = r.epoch.pause();
- defer r.epoch.unpause(was);
+ // The emulator is the authority's: on the C heap, outside the
+ // rollback epoch, so a copy held now never saves or puts back any
+ // of what this writes (State.gpa).
switch (m.kind) {
kind_delta => {
const t0 = nowNs();
- const applied = sc.rep.apply(r.coreGpa(), terminal.terminalIo(), &state.vt, m.payload) catch |err| {
+ const applied = sc.rep.apply(state.gpa, terminal.terminalIo(), &state.vt, m.payload) catch |err| {
if (err != error.BaseMismatch) r.fail("a terminal's delta did not apply");
if (sc.refused) return null;
sc.refused = true;
@@ -763,7 +762,7 @@ pub const Replica = struct {
},
kind_rows => {
sc.asked = null;
- sc.rep.applyRows(r.coreGpa(), &state.vt, m.payload) catch r.fail("a terminal's rows did not apply");
+ sc.rep.applyRows(state.gpa, &state.vt, m.payload) catch r.fail("a terminal's rows did not apply");
c.shell_rows.markStale(pane);
return null;
},