Switch over to the IO thread. A messy commit!

This commit is contained in:
Mitchell Hashimoto
2022-11-05 09:39:56 -07:00
parent 5cb6ebe34d
commit f2d9475d5d
3 changed files with 176 additions and 642 deletions

File diff suppressed because it is too large Load Diff

View File

@ -162,7 +162,8 @@ fn drainMailbox(self: *Thread) !void {
log.debug("mailbox message={}", .{message});
switch (message) {
.resize => |v| try self.impl.resize(v.grid_size, v.screen_size),
.small_write => |v| try self.impl.queueWrite(v.data[0..v.len]),
.write_small => |v| try self.impl.queueWrite(v.data[0..v.len]),
.write_stable => |v| try self.impl.queueWrite(v),
}
}
}

View File

@ -1,11 +1,10 @@
const std = @import("std");
const Allocator = std.mem.Allocator;
const renderer = @import("../renderer.zig");
const terminal = @import("../terminal/main.zig");
/// The messages that can be sent to an IO thread.
pub const IO = union(enum) {
pub const SmallWriteArray = [22]u8;
/// Resize the window.
resize: struct {
grid_size: renderer.GridSize,
@ -13,10 +12,35 @@ pub const IO = union(enum) {
},
/// Write where the data fits in the union.
small_write: struct {
data: [22]u8,
write_small: WriteReq.Small,
/// Write where the data pointer is stable.
write_stable: []const u8,
};
/// Represents a write request.
pub const WriteReq = union(enum) {
pub const Small = struct {
pub const Array = [22]u8;
data: Array,
len: u8,
},
};
pub const Alloc = struct {
alloc: Allocator,
data: []u8,
};
/// A small write where the data fits into this union size.
small: Small,
/// A stable pointer so we can just pass the slice directly through.
/// This is useful i.e. for const data.
stable: []const u8,
/// Allocated and must be freed with the provided allocator. This
/// should be rarely used.
alloc: Alloc,
};
test {