widgets(terminal): prevent deadlock in draw
The draw method could obtain a lock but never free it due to the logic of the if statement.
This commit is contained in:
parent
3a382eacdb
commit
11ae2e7b29
1 changed files with 5 additions and 2 deletions
|
@ -166,8 +166,11 @@ pub fn resize(self: *Terminal, ws: Winsize) !void {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn draw(self: *Terminal, win: vaxis.Window) !void {
|
pub fn draw(self: *Terminal, win: vaxis.Window) !void {
|
||||||
if (self.back_mutex.tryLock() and !self.mode.sync) {
|
if (self.back_mutex.tryLock()) {
|
||||||
defer self.back_mutex.unlock();
|
defer self.back_mutex.unlock();
|
||||||
|
// We keep this as a separate condition so we don't deadlock by obtaining the lock but not
|
||||||
|
// having sync
|
||||||
|
if (!self.mode.sync)
|
||||||
try self.back_screen.copyTo(&self.front_screen);
|
try self.back_screen.copyTo(&self.front_screen);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue