update config messages use pointers now to make messages small again

This commit is contained in:
Mitchell Hashimoto
2023-03-19 10:48:42 -07:00
parent e84fb55e2c
commit b0b3b0af2d
8 changed files with 41 additions and 18 deletions

View File

@ -569,17 +569,30 @@ fn changeConfig(self: *Surface, config: *const configpkg.Config) !void {
self.config.deinit(); self.config.deinit();
self.config = derived; self.config = derived;
// We need to store our configs in a heap-allocated pointer so that
// our messages aren't huge.
var renderer_config_ptr = try self.alloc.create(Renderer.DerivedConfig);
errdefer self.alloc.destroy(renderer_config_ptr);
var termio_config_ptr = try self.alloc.create(termio.Impl.DerivedConfig);
errdefer self.alloc.destroy(termio_config_ptr);
// Update our derived configurations for the renderer and termio, // Update our derived configurations for the renderer and termio,
// then send them a message to update. // then send them a message to update.
var renderer_config = try Renderer.DerivedConfig.init(self.alloc, config); renderer_config_ptr.* = try Renderer.DerivedConfig.init(self.alloc, config);
errdefer renderer_config.deinit(); errdefer renderer_config_ptr.deinit();
var termio_config = try termio.Impl.DerivedConfig.init(self.alloc, config); termio_config_ptr.* = try termio.Impl.DerivedConfig.init(self.alloc, config);
errdefer termio_config.deinit(); errdefer termio_config_ptr.deinit();
_ = self.renderer_thread.mailbox.push(.{ _ = self.renderer_thread.mailbox.push(.{
.change_config = renderer_config, .change_config = .{
.alloc = self.alloc,
.ptr = renderer_config_ptr,
},
}, .{ .forever = {} }); }, .{ .forever = {} });
_ = self.io_thread.mailbox.push(.{ _ = self.io_thread.mailbox.push(.{
.change_config = termio_config, .change_config = .{
.alloc = self.alloc,
.ptr = termio_config_ptr,
},
}, .{ .forever = {} }); }, .{ .forever = {} });
// With mailbox messages sent, we have to wake them up so they process it. // With mailbox messages sent, we have to wake them up so they process it.

View File

@ -725,8 +725,8 @@ fn drawCells(
} }
/// Update the configuration. /// Update the configuration.
pub fn changeConfig(self: *Metal, config: DerivedConfig) !void { pub fn changeConfig(self: *Metal, config: *DerivedConfig) !void {
self.config = config; self.config = config.*;
} }
/// Resize the screen. /// Resize the screen.

View File

@ -1233,8 +1233,8 @@ fn gridSize(self: *const OpenGL, screen_size: renderer.ScreenSize) renderer.Grid
} }
/// Update the configuration. /// Update the configuration.
pub fn changeConfig(self: *OpenGL, config: DerivedConfig) !void { pub fn changeConfig(self: *OpenGL, config: *DerivedConfig) !void {
self.config = config; self.config = config.*;
} }
/// Set the screen size for rendering. This will update the projection /// Set the screen size for rendering. This will update the projection

View File

@ -257,7 +257,8 @@ fn drainMailbox(self: *Thread) !void {
}, },
.change_config => |config| { .change_config => |config| {
try self.renderer.changeConfig(config); defer config.alloc.destroy(config.ptr);
try self.renderer.changeConfig(config.ptr);
}, },
} }
} }

View File

@ -24,5 +24,8 @@ pub const Message = union(enum) {
screen_size: renderer.ScreenSize, screen_size: renderer.ScreenSize,
/// The derived configuration to update the renderer with. /// The derived configuration to update the renderer with.
change_config: renderer.Renderer.DerivedConfig, change_config: struct {
alloc: Allocator,
ptr: *renderer.Renderer.DerivedConfig,
},
}; };

View File

@ -218,9 +218,8 @@ pub fn threadExit(self: *Exec, data: ThreadData) void {
} }
/// Update the configuration. /// Update the configuration.
pub fn changeConfig(self: *Exec, config: DerivedConfig) !void { pub fn changeConfig(self: *Exec, config: *DerivedConfig) !void {
var copy = config; defer config.deinit();
defer copy.deinit();
// Update the configuration that we know about. // Update the configuration that we know about.
// //

View File

@ -150,7 +150,10 @@ fn drainMailbox(self: *Thread) !void {
log.debug("mailbox message={}", .{message}); log.debug("mailbox message={}", .{message});
switch (message) { switch (message) {
.change_config => |config| try self.impl.changeConfig(config), .change_config => |config| {
defer config.alloc.destroy(config.ptr);
try self.impl.changeConfig(config.ptr);
},
.resize => |v| self.handleResize(v), .resize => |v| self.handleResize(v),
.clear_screen => |v| try self.impl.clearScreen(v.history), .clear_screen => |v| try self.impl.clearScreen(v.history),
.write_small => |v| try self.impl.queueWrite(v.data[0..v.len]), .write_small => |v| try self.impl.queueWrite(v.data[0..v.len]),

View File

@ -29,8 +29,12 @@ pub const Message = union(enum) {
padding: renderer.Padding, padding: renderer.Padding,
}; };
/// The derived configuration to update the implementation with. /// The derived configuration to update the implementation with. This
change_config: termio.Impl.DerivedConfig, /// is allocated via the allocator and is expected to be freed when done.
change_config: struct {
alloc: Allocator,
ptr: *termio.Impl.DerivedConfig,
},
/// Resize the window. /// Resize the window.
resize: Resize, resize: Resize,