do not block channel send while draining channel

This commit is contained in:
Mitchell Hashimoto
2022-11-20 20:16:40 -08:00
parent d213c1a939
commit a15afa8211
3 changed files with 14 additions and 29 deletions

View File

@ -143,10 +143,7 @@ pub fn run(self: *App) !void {
/// Drain the mailbox.
fn drainMailbox(self: *App) !void {
var drain = self.mailbox.drain();
defer drain.deinit();
while (drain.next()) |message| {
while (self.mailbox.pop()) |message| {
log.debug("mailbox message={s}", .{@tagName(message)});
switch (message) {
.new_window => |msg| _ = try self.newWindow(msg),

View File

@ -238,14 +238,7 @@ fn drainMailbox(self: *Thread) !void {
const zone = trace(@src());
defer zone.end();
// This holds the mailbox lock for the duration of the drain. The
// expectation is that all our message handlers will be non-blocking
// ENOUGH to not mess up throughput on producers.
var drain = self.mailbox.drain();
defer drain.deinit();
while (drain.next()) |message| {
while (self.mailbox.pop()) |message| {
log.debug("mailbox message={}", .{message});
switch (message) {
.focus => |v| {

View File

@ -162,24 +162,19 @@ fn drainMailbox(self: *Thread) !void {
// expectation is that all our message handlers will be non-blocking
// ENOUGH to not mess up throughput on producers.
var redraw: bool = false;
{
var drain = self.mailbox.drain();
defer drain.deinit();
while (self.mailbox.pop()) |message| {
// If we have a message we always redraw
redraw = true;
while (drain.next()) |message| {
// If we have a message we always redraw
redraw = true;
log.debug("mailbox message={}", .{message});
switch (message) {
.resize => |v| try self.impl.resize(v.grid_size, v.screen_size, v.padding),
.write_small => |v| try self.impl.queueWrite(v.data[0..v.len]),
.write_stable => |v| try self.impl.queueWrite(v),
.write_alloc => |v| {
defer v.alloc.free(v.data);
try self.impl.queueWrite(v.data);
},
}
log.debug("mailbox message={}", .{message});
switch (message) {
.resize => |v| try self.impl.resize(v.grid_size, v.screen_size, v.padding),
.write_small => |v| try self.impl.queueWrite(v.data[0..v.len]),
.write_stable => |v| try self.impl.queueWrite(v),
.write_alloc => |v| {
defer v.alloc.free(v.data);
try self.impl.queueWrite(v.data);
},
}
}