summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/Store.zig46
-rw-r--r--src/tape.zig3
2 files changed, 22 insertions, 27 deletions
diff --git a/src/Store.zig b/src/Store.zig
index 87dba4f7..2bb9fcf0 100644
--- a/src/Store.zig
+++ b/src/Store.zig
@@ -111,11 +111,7 @@ fn ioOf() std.Io {
/// store under a mount of this session's own tree is answered by this
/// session. Only the call: while a step is out nothing may change the core,
/// so the store and Recent change between these, never inside one.
-fn host(comptime f: anytype, args: anytype) @typeInfo(@TypeOf(f)).@"fn".return_type.? {
- pardes.turn.yield();
- defer pardes.turn.back();
- return @call(.auto, f, args);
-}
+const host = pardes.tape.out;
const cwd = std.Io.Dir.cwd;
const File = std.Io.File;
@@ -293,6 +289,17 @@ fn parseMeta(body: []const u8) ?Meta {
return m;
}
+/// An `x` record: a session's closed pane brought back, `<session> <serial>`.
+const Reopened = struct { session: u64, serial: u32 };
+
+fn parseReopened(b: []const u8) ?Reopened {
+ const sp = std.mem.indexOfScalar(u8, b, ' ') orelse return null;
+ return .{
+ .session = std.fmt.parseInt(u64, b[0..sp], 16) catch return null,
+ .serial = std.fmt.parseInt(u32, b[sp + 1 ..], 10) catch return null,
+ };
+}
+
/// The store read at start.
pub fn load(s: *Store, p: *Pardes) void {
const path = s.path orelse return;
@@ -418,10 +425,8 @@ fn apply(s: *Store, p: *Pardes, r: *Reader, rec: Rec) bool {
if (rec.len > 64) return false;
const b = r.bytes(rec.body, rec.len) orelse return false;
if (std.hash.Crc32.hash(b) != rec.crc) return false;
- const sp = std.mem.indexOfScalar(u8, b, ' ') orelse return false;
- const session = std.fmt.parseInt(u64, b[0..sp], 16) catch return false;
- const serial = std.fmt.parseInt(u32, b[sp + 1 ..], 10) catch return false;
- if (session == s.session) s.unlist(gpa, serial);
+ const x = parseReopened(b) orelse return false;
+ if (x.session == s.session) s.unlist(gpa, x.serial);
},
// A header in the middle is no record.
'h' => return false,
@@ -638,7 +643,7 @@ pub fn flush(s: *Store, p: *Pardes, wait: bool) void {
}
host(File.writePositionalAll, .{ file, io, s.pending.items, st.size }) catch {
// Out of disk: kept for no one, as the old list was.
- s.dropPending(gpa);
+ s.dropPending();
return;
};
for (s.closed.items) |*c| if (c.pending_at) |off| {
@@ -654,12 +659,10 @@ pub fn flush(s: *Store, p: *Pardes, wait: bool) void {
fn forget(s: *Store, p: *Pardes) void {
for (p.recent.entries.items) |*e| e.changed = false;
p.recent.dirty = false;
- s.pending.clearRetainingCapacity();
- for (s.closed.items) |*c| c.pending_at = null;
+ s.dropPending();
}
-fn dropPending(s: *Store, gpa: std.mem.Allocator) void {
- _ = gpa;
+fn dropPending(s: *Store) void {
s.pending.clearRetainingCapacity();
for (s.closed.items) |*c| c.pending_at = null;
}
@@ -675,7 +678,7 @@ fn alive(pid: i32) bool {
fn compact(s: *Store, p: *Pardes, file: File, st: File.Stat, path: []const u8) void {
const gpa = p.recentGpa();
const io = ioOf();
- defer s.dropPending(gpa);
+ defer s.dropPending();
const buf = gpa.alloc(u8, 64 << 10) catch return;
defer gpa.free(buf);
var r: Reader = .{ .file = file, .io = io, .size = st.size, .buf = buf };
@@ -684,8 +687,7 @@ fn compact(s: *Store, p: *Pardes, file: File, st: File.Stat, path: []const u8) v
const Live = struct { at: u64, end: u64, session: u64, pid: i32, serial: u32, keep: bool = false };
var lives: std.ArrayList(Live) = .empty;
defer lives.deinit(gpa);
- const Gone = struct { session: u64, serial: u32 };
- var gone: std.ArrayList(Gone) = .empty;
+ var gone: std.ArrayList(Reopened) = .empty;
defer gone.deinit(gpa);
var at: u64 = 0;
while (at < r.size) {
@@ -699,13 +701,7 @@ fn compact(s: *Store, p: *Pardes, file: File, st: File.Stat, path: []const u8) v
switch (rec.kind) {
'r' => if (recent.List.parseLine(b)) |e| fold.note(gpa, e.path, e.nums[0], e.nums[1], e.nums[2], e.nums[3]),
'c' => if (parseMeta(b)) |m| lives.append(gpa, .{ .at = rec.at, .end = rec.end(), .session = m.session, .pid = m.pid, .serial = m.serial }) catch {},
- 'x' => {
- const sp = std.mem.indexOfScalar(u8, b, ' ') orelse continue;
- gone.append(gpa, .{
- .session = std.fmt.parseInt(u64, b[0..sp], 16) catch continue,
- .serial = std.fmt.parseInt(u32, b[sp + 1 ..], 10) catch continue,
- }) catch {};
- },
+ 'x' => if (parseReopened(b)) |x| gone.append(gpa, x) catch {},
else => {},
}
},
@@ -1076,11 +1072,9 @@ test "store: a closed pane comes back where it was, its rows from the pane that
p.newScratchBelow(0);
const sid = p.active;
@import("File.zig").setContent(p, &p.panes[sid].?.file.?, try p.gpa.dupe(u8, "kept text\n"));
- const other = p.col_panes[0][1];
p.newScratchBelow(0);
try testing.expect(layout.splitColumn(p, p.active, p.active, false));
const far = p.active;
- _ = other;
p.active = 0;
// Made outside a step: announced as a step's end would.
pardes.ctlfs.events.announce(p);
diff --git a/src/tape.zig b/src/tape.zig
index 56789f44..fe16406e 100644
--- a/src/tape.zig
+++ b/src/tape.zig
@@ -993,7 +993,8 @@ fn overNow(since_ns: u64, budget_ns: u64) bool {
return pardes.FrameStats.nowNs() -| since_ns > budget_ns;
}
-fn out(comptime f: anytype, args: anytype) @typeInfo(@TypeOf(f)).@"fn".return_type.? {
+/// One host call, `f(args)`, made out of the turn (pardes.turn).
+pub fn out(comptime f: anytype, args: anytype) @typeInfo(@TypeOf(f)).@"fn".return_type.? {
pardes.turn.yield();
defer pardes.turn.back();
return @call(.auto, f, args);