diff options
Diffstat (limited to 'src/gui')
| -rw-r--r-- | src/gui/gui.zig | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/src/gui/gui.zig b/src/gui/gui.zig index d935b5fd..b34b314d 100644 --- a/src/gui/gui.zig +++ b/src/gui/gui.zig @@ -937,6 +937,8 @@ const Queue = struct { completion_len: usize = 0, fn lock(q: *Queue) void { + // unreachable failures: pthread calls on this queue's own initialised, non-recursive + // mutex and condition fail only on misuse (EINVAL, EDEADLK), never on input. std.debug.assert(libc.pthread_mutex_lock(&q.mutex) == .SUCCESS); } @@ -1061,9 +1063,19 @@ const Queue = struct { } fn take(q: *Queue) MessageBatch { + var batch: MessageBatch = .{}; + q.takeInto(&batch); + return batch; + } + + /// `take` into a batch the caller keeps: an idle wakeup copies nothing + /// (the batch is some 20 KB, and was built and returned by value each + /// time). + fn takeInto(q: *Queue, batch: *MessageBatch) void { + batch.len = 0; q.lock(); defer q.unlock(); - var batch: MessageBatch = .{}; + if (q.len == 0 and !q.files_changed and q.completion_len == 0) return; while (q.len > 0) { batch.items[batch.len] = q.items[q.head]; batch.len += 1; @@ -1080,7 +1092,6 @@ const Queue = struct { batch.len += q.completion_len; q.completion_len = 0; std.debug.assert(libc.pthread_cond_broadcast(&q.space) == .SUCCESS); - return batch; } fn discardCompletions(q: *Queue) void { @@ -3999,6 +4010,8 @@ const Shell = struct { ptys: *[pardes.MAX_PANES]?Pty, gens: *[pardes.MAX_PANES]u32, queue: *Queue, + /// What drainQueue takes each wakeup, kept rather than rebuilt. + batch: MessageBatch = .{}, pipe_tasks: *PipeTasks, inotify_fd: c_int, watches: *file_watch.Table, @@ -4153,7 +4166,8 @@ const Shell = struct { s.reconcilePtys(); // After this batch's output, which an exit is told behind. defer s.takeExits(); - var msgs = s.queue.take(); + s.queue.takeInto(&s.batch); + const msgs = &s.batch; var check_files = false; for (msgs.slice()) |m| switch (m) { .output => |o| { @@ -8322,6 +8336,7 @@ fn captureFrame(g: *Gui, gpa: std.mem.Allocator, cmd: *c.SDL_GPUCommandBuffer, t const pixels: [*]const u8 = @ptrCast(mapped); try writeCapturePpm(g, gpa, pixels[0..size], sw, sh, "latest"); var name: [24]u8 = undefined; + // unreachable below: "transition-" or "frame-" and a u32 fit 24 if (transition) |frame| try writeCapturePpm(g, gpa, pixels[0..size], sw, sh, std.fmt.bufPrint(&name, "transition-{d}", .{frame}) catch unreachable); if (g.capture_series) try writeCapturePpm(g, gpa, pixels[0..size], sw, sh, std.fmt.bufPrint(&name, "frame-{d:0>5}", .{g.captured}) catch unreachable); g.captured +%= 1; |
