summaryrefslogtreecommitdiff
path: root/src/host_io.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/host_io.zig')
-rw-r--r--src/host_io.zig35
1 files changed, 35 insertions, 0 deletions
diff --git a/src/host_io.zig b/src/host_io.zig
index b32fff55..f5d6f375 100644
--- a/src/host_io.zig
+++ b/src/host_io.zig
@@ -48,6 +48,9 @@ pub const Host = struct {
open_link: ?*const fn (ctx: ?*anyopaque, url: []const u8) void = null,
lsp: ?*const fn (ctx: ?*anyopaque, req: Lsp.Request) void = null,
pipe: ?*const fn (ctx: ?*anyopaque, id: u32) void = null,
+ /// Start the streaming search of this generation on a worker
+ /// (pardes.Stream.start); absent, it runs on the loop.
+ search: ?*const fn (ctx: ?*anyopaque, gen: u32) void = null,
};
};
@@ -129,6 +132,9 @@ pub const Inbox = struct {
lsp: struct { id: u32, rows: ?[]u8 },
lsp_status: []u8,
pipe: selection_pipe.Response,
+ /// A streaming search's rows (pardes.Stream), of whatever generation:
+ /// the core drops a stale one.
+ search: pardes.Stream.Batch,
files_changed,
fs_ready,
@@ -141,6 +147,7 @@ pub const Inbox = struct {
var response = response_value;
response.deinit(gpa);
},
+ .search => |b| b.deinit(gpa),
.eof, .files_changed, .fs_ready => {},
}
}
@@ -425,6 +432,34 @@ pub const Inbox = struct {
q.push(.{ .pipe = response });
}
+ /// A streaming search's batch (pardes.Stream.start's sink). Never
+ /// dropped for want of room, as output is not: the worker waits for
+ /// room, a wait its cancel ends (false: it stops).
+ pub fn pushSearch(ctx: ?*anyopaque, batch: pardes.Stream.Batch) bool {
+ const q: *Inbox = @ptrCast(@alignCast(ctx.?));
+ q.lock();
+ while (!q.closed and q.len >= output_capacity) {
+ q.waiting += 1;
+ q.space.wait(q.io, &q.mutex) catch {
+ q.waiting -= 1;
+ q.unlock();
+ batch.deinit(q.gpa);
+ return false;
+ };
+ q.waiting -= 1;
+ }
+ if (q.closed) {
+ q.unlock();
+ batch.deinit(q.gpa);
+ return false;
+ }
+ q.items[(q.head + q.len) % q.items.len] = .{ .search = batch };
+ q.len += 1;
+ q.unlock();
+ q.wake();
+ return true;
+ }
+
/// A watched child exited (setExitWake): wake the loop, which takes it.
pub fn wakeForExit(ctx: ?*anyopaque) void {
const q: *Inbox = @ptrCast(@alignCast(ctx.?));