mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-15 00:06:09 +03:00
Merge pull request #861 from mitchellh/writer-block
termio: wake up writer thread if the writer mailbox is full
This commit is contained in:
@ -60,7 +60,9 @@ pub fn Stream(comptime Handler: type) type {
|
|||||||
for (actions) |action_opt| {
|
for (actions) |action_opt| {
|
||||||
const action = action_opt orelse continue;
|
const action = action_opt orelse continue;
|
||||||
|
|
||||||
|
// if (action != .print) {
|
||||||
// log.info("action: {}", .{action});
|
// log.info("action: {}", .{action});
|
||||||
|
// }
|
||||||
|
|
||||||
// If this handler handles everything manually then we do nothing
|
// If this handler handles everything manually then we do nothing
|
||||||
// if it can be processed.
|
// if it can be processed.
|
||||||
|
@ -1398,7 +1398,21 @@ const StreamHandler = struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
inline fn messageWriter(self: *StreamHandler, msg: termio.Message) void {
|
inline fn messageWriter(self: *StreamHandler, msg: termio.Message) void {
|
||||||
|
// Try to write to the mailbox with an instant timeout. If the
|
||||||
|
// mailbox is full, then we wake up the writer thread mid-processing
|
||||||
|
// so it can process the message and then try again with a forever
|
||||||
|
// wait.
|
||||||
|
if (self.ev.writer_mailbox.push(msg, .{ .instant = {} }) == 0) {
|
||||||
|
self.ev.writer_wakeup.notify() catch |err| {
|
||||||
|
log.warn("failed to wake up writer, data will be dropped err={}", .{err});
|
||||||
|
return;
|
||||||
|
};
|
||||||
|
|
||||||
_ = self.ev.writer_mailbox.push(msg, .{ .forever = {} });
|
_ = self.ev.writer_mailbox.push(msg, .{ .forever = {} });
|
||||||
|
}
|
||||||
|
|
||||||
|
// Normally, we just flag this true to wake up the writer thread
|
||||||
|
// once per batch of data.
|
||||||
self.writer_messaged = true;
|
self.writer_messaged = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user