summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/Kind.zig5
-rw-r--r--core/replica.zig19
2 files changed, 18 insertions, 6 deletions
diff --git a/core/Kind.zig b/core/Kind.zig
index 9844369d..2bf8e9fb 100644
--- a/core/Kind.zig
+++ b/core/Kind.zig
@@ -1253,9 +1253,12 @@ var ready: std.ArrayListUnmanaged(*host_io.KindJob) = .empty;
/// A draw done on a worker, back on the loop: kept for its pane's next
/// paint, a frame owed. One of another core's (a client joined again
-/// since) is dropped: the new core's pane asked its own.
+/// since), or of a pane closed since, is dropped: the new core's pane asked
+/// its own.
pub fn landDraw(p: *Pardes, j: *host_io.KindJob) void {
if (j.draw != p) return j.drop();
+ // Its pane closed meanwhile: no paint of it would ever take it.
+ if (if (p.panes[j.pane]) |pane| pane.serial != j.serial else true) return j.drop();
ready.append(heap, j) catch return j.drop();
p.needs_frame = true;
}
diff --git a/core/replica.zig b/core/replica.zig
index ae2616b7..fb3a81c4 100644
--- a/core/replica.zig
+++ b/core/replica.zig
@@ -1900,7 +1900,7 @@ pub const Peer = struct {
}
}
- fn take(peer: *Peer, tag: u8, payload: []const u8) bool {
+ pub fn take(peer: *Peer, tag: u8, payload: []const u8) bool {
const t = std.enums.fromInt(wire.ClientTag, tag) orelse return false;
switch (t) {
.hello => return false,
@@ -2047,6 +2047,14 @@ pub const Peers = struct {
/// it records: what each was sent.
screens: Screens = undefined,
msgs: std.ArrayListUnmanaged([]u8) = .empty,
+ /// False: its clients' links are in this process's memory, a thread
+ /// for none of them (the soak's, test/replicas.zig): what a client's
+ /// writer would write (its join, then `out`) and its reader read
+ /// (`Peer.take`, then `.gone` posted) are its driver's to do.
+ threads: bool = true,
+ /// After each flush of a client's terminals, told: the soak's record
+ /// of each terminal as each version left it (test/replicas.zig).
+ flushed: ?struct { ctx: *anyopaque, f: *const fn (*anyopaque, *Pardes, *Screens) void } = null,
pub const Note = union(enum) { join: Joining, input: Msg, screen: Msg, gone: *Peer, check: *Peer, joined: *Peer };
/// A connection to join, and the view it joins again for, if it does.
@@ -2059,7 +2067,7 @@ pub const Peers = struct {
return n;
}
- fn post(ps: *Peers, note: Note) void {
+ pub fn post(ps: *Peers, note: Note) void {
ps.lock.lockUncancelable(ps.io);
ps.inbox.append(ps.gpa, note) catch {
ps.lock.unlock(ps.io);
@@ -2186,6 +2194,7 @@ pub const Peers = struct {
.flush => ps.screens.flush(core, peer.sid, peer.view, &ps.msgs),
.fill => ps.screens.fill(core, peer.sid, &ps.msgs),
}) catch return;
+ if (what == .flush) if (ps.flushed) |h| h.f(h.ctx, core, &ps.screens);
for (ps.msgs.items) |m| {
const head = wire.header(@backingInt(wire.ServerTag.screen), m.len);
peer.send(&.{ &head, m });
@@ -2270,9 +2279,9 @@ pub const Peers = struct {
// The session's digest as dumped, for the joiner to check its load by.
const digest = tape.digestOf(core);
peer.welcome_len = (wire.encodeServer(&peer.welcome, .{ .welcome = .{ .pid = @intCast(libc.getpid()), .session = ps.name[0..@min(ps.name.len, wire.max_name)], .client = peer.id, .view = k, .dump_len = whole, .gmtoff = gmtoff(), .digest = digest, .semantics = wire.semantics, .blobs = @intCast(blobs.items.len) } }) catch unreachable).len;
- peer.writer = std.Thread.spawn(.{}, Peer.writeLoop, .{peer}) catch null;
- peer.reader = std.Thread.spawn(.{}, Peer.readLoop, .{peer}) catch null;
- if (peer.writer == null or peer.reader == null) {
+ if (ps.threads) peer.writer = std.Thread.spawn(.{}, Peer.writeLoop, .{peer}) catch null;
+ if (ps.threads) peer.reader = std.Thread.spawn(.{}, Peer.readLoop, .{peer}) catch null;
+ if (ps.threads and (peer.writer == null or peer.reader == null)) {
ps.letGo(peer);
core.undrawn &= ~(@as(u8, 1) << @intCast(k));
core.closeView(k);