diff options
Diffstat (limited to 'src/host_io.zig')
| -rw-r--r-- | src/host_io.zig | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/src/host_io.zig b/src/host_io.zig index b086b5fe..d199c839 100644 --- a/src/host_io.zig +++ b/src/host_io.zig @@ -80,6 +80,8 @@ pub const Host = struct { /// A kind's job (Effect.job), taken off its pane: its input, its kind's /// `job_run` and generation; run on a worker (or here), its answer the /// core's `job` event. Its library is held until it lands (Addon.holdJob). +/// A draw (api.draw, `draw`) is one of this process's alone: never an +/// event, its answer kept for the pane's next paint (Kind.landDraw). pub const KindJob = struct { gpa: std.mem.Allocator, pane: u8, @@ -92,6 +94,8 @@ pub const KindJob = struct { arena: std.heap.ArenaAllocator, out: []u8 = &.{}, id: u32 = 0, + /// A draw's: the core it was asked in. + draw: ?*const pardes.Pardes = null, pub fn take(p: *pardes.Pardes, pane: u8, serial: u32, token: u32) ?*KindJob { const pn = p.panes[pane] orelse return null; @@ -123,6 +127,7 @@ pub const KindJob = struct { /// Its answer to the core, and it gone. pub fn land(j: *KindJob, p: *pardes.Pardes) void { + if (j.draw != null) return pardes.Kind.landDraw(p, j); p.update(.{ .job = .{ .pane = j.pane, .serial = j.serial, .token = j.token, .gen = j.gen, .bytes = j.out } }); j.drop(); } @@ -137,6 +142,12 @@ pub const KindJob = struct { /// On a worker of `io`, posting itself to `sink` done: a host's `job`. pub fn start(io: std.Io, p: *pardes.Pardes, tasks: *selection_pipe.Tasks, pane: u8, serial: u32, token: u32, ctx: ?*anyopaque, sink: *const fn (?*anyopaque, *KindJob) void) void { const j = take(p, pane, serial, token) orelse return; + if (!go(io, tasks, j, ctx, sink)) here(j, p); + } + + /// `j` on a worker of `io`, posting itself to `sink` done; false when + /// none could take it. + pub fn go(io: std.Io, tasks: *selection_pipe.Tasks, j: *KindJob, ctx: ?*anyopaque, sink: *const fn (?*anyopaque, *KindJob) void) bool { next_id +%= 1; j.id = next_id | 0x8000_0000; const work = struct { @@ -145,9 +156,10 @@ pub const KindJob = struct { s(c, job); } }.work; - if (tasks.full()) return here(j, p); - const future = io.concurrent(work, .{ j, ctx, sink }) catch return here(j, p); + if (tasks.full()) return false; + const future = io.concurrent(work, .{ j, ctx, sink }) catch return false; _ = tasks.add(.{ .id = j.id, .future = future }); + return true; } var next_id: u32 = 0; |
