diff options
Diffstat (limited to 'src/replica.zig')
| -rw-r--r-- | src/replica.zig | 73 |
1 files changed, 6 insertions, 67 deletions
diff --git a/src/replica.zig b/src/replica.zig index f58a4b27..71528fc4 100644 --- a/src/replica.zig +++ b/src/replica.zig @@ -947,9 +947,6 @@ pub const Replica = struct { c.update(in.event); c.step(); p.terminal = r.t.screen_state and (keyboard or r.t.touched); - // No digest is taken here: a blob born under the copy and digested - // keeps its word past the epoch's free of it (src/walk.zig), and a - // later blob at that address read as it. const clean = tape.endSpeculation(&r.t); const dt = nowNs() - t0; // Where a blob was written, should one be: the input that did. @@ -1455,7 +1452,7 @@ pub const Peer = struct { /// state, then the blobs it says it lacks; what follows the join goes /// in a cheaper frame. The hashing is this thread's, never the step's. /// ponytail: a blob is hashed again at every far join, 3.6 GB/s; a - /// session's join after its first would keep them, beside its words. + /// session's join after its first could keep them. fn farJoin(peer: *Peer) bool { const gpa = peer.peers.gpa; peer.z = zstd.compressor(6, 23) orelse return false; @@ -1736,14 +1733,8 @@ pub const Peers = struct { /// it records: what each was sent. screens: Screens = undefined, msgs: std.ArrayListUnmanaged([]u8) = .empty, - /// Clients waiting to join while the session's texts are hashed - /// (`joins`), the texts and the thread hashing them. - held: std.ArrayListUnmanaged(Joining) = .empty, - texts: std.ArrayListUnmanaged([]const u8) = .empty, - hasher: ?std.Thread = null, - rounds: u8 = 0, - pub const Note = union(enum) { join: Joining, input: Msg, screen: Msg, gone: *Peer, check: *Peer, joined: *Peer, hashed }; + 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. pub const Joining = daemon.Joining; pub const Msg = struct { peer: *Peer, msg: []u8 }; @@ -1761,7 +1752,7 @@ pub const Peers = struct { switch (note) { .join => |j| _ = libc.close(j.fd), .input, .screen => |in| ps.gpa.free(in.msg), - .gone, .check, .joined, .hashed => {}, + .gone, .check, .joined => {}, } return; }; @@ -1812,17 +1803,7 @@ pub const Peers = struct { ps.mail.store(false, .release); ps.lock.unlock(ps.io); for (ps.taken.items) |note| switch (note) { - .join => |j| { - ps.held.append(ps.gpa, j) catch { - daemon.refuseReplica(j.fd, "out of memory"); - continue; - }; - ps.joins(core); - }, - .hashed => { - ps.unhashedDone(); - ps.joins(core); - }, + .join => |j| ps.join(core, j), .input => |in| { ps.input(core, in.peer, in.msg); ps.gpa.free(in.msg); @@ -1885,42 +1866,6 @@ pub const Peers = struct { } } - /// The clients waiting to join, joined, once the texts the session - /// never digested have their words (`walk.unhashed`): those are hashed - /// on a thread of their own, pinned meanwhile, and the joins wait a - /// boundary or two for them, the session's step never. A second round - /// joins whatever is left. - fn joins(ps: *Peers, core: *Pardes) void { - if (ps.hasher != null or ps.held.items.len == 0) return; - if (ps.rounds < 2) { - walk.unhashed(Pardes, core, &ps.texts); - if (ps.texts.items.len > 0) { - for (ps.texts.items) |b| pardes.memory.pin(b); - if (std.Thread.spawn(.{}, hashTexts, .{ps})) |t| { - ps.hasher = t; - ps.rounds += 1; - return; - } else |_| ps.unhashedDone(); - } - } - ps.rounds = 0; - for (ps.held.items) |j| ps.join(core, j); - ps.held.clearRetainingCapacity(); - } - - fn hashTexts(ps: *Peers) void { - walk.makeWords(ps.texts.items); - ps.post(.hashed); - } - - /// The hashing thread joined, its texts unpinned. - fn unhashedDone(ps: *Peers) void { - if (ps.hasher) |t| t.join(); - ps.hasher = null; - for (ps.texts.items) |b| pardes.memory.unpin(b); - ps.texts.clearRetainingCapacity(); - } - fn join(ps: *Peers, core: *Pardes, joining: Joining) void { const fd = joining.fd; const t0 = nowNs(); @@ -2064,7 +2009,7 @@ pub const Peers = struct { const mine = switch (ps.inbox.items[i]) { .input, .screen => |in| in.peer == peer, .gone, .check, .joined => |p| p == peer, - .join, .hashed => false, + .join => false, }; if (!mine) { i += 1; @@ -2145,10 +2090,6 @@ pub const Peers = struct { /// ...each view kept for its client if `again` (an Upgrade's). fn drop(ps: *Peers, core: *Pardes, again: bool) void { - ps.unhashedDone(); - for (ps.held.items) |j| _ = libc.close(j.fd); - ps.held.clearRetainingCapacity(); - ps.rounds = 0; for (&ps.list) |*slot| if (slot.*) |peer| { slot.* = null; core.undrawn &= ~(@as(u8, 1) << @intCast(peer.view)); @@ -2161,7 +2102,7 @@ pub const Peers = struct { for (ps.inbox.items) |note| switch (note) { .join => |j| _ = libc.close(j.fd), .input, .screen => |in| ps.gpa.free(in.msg), - .gone, .check, .joined, .hashed => {}, + .gone, .check, .joined => {}, }; ps.inbox.clearRetainingCapacity(); ps.lock.unlock(ps.io); @@ -2175,8 +2116,6 @@ pub const Peers = struct { ps.input_ns.deinit(ps.gpa); ps.boundary_ns.deinit(ps.gpa); ps.msgs.deinit(ps.gpa); - ps.held.deinit(ps.gpa); - ps.texts.deinit(std.heap.c_allocator); ps.each_join.deinit(ps.gpa); } |
