From a91a3f2dce121a179a9371cd0ad1e548cf3d7731 Mon Sep 17 00:00:00 2001 From: Joe Wilm Date: Thu, 29 Dec 2016 21:38:22 -0500 Subject: Fix pty read sometimes not triggering draw There was a lot of complexity around the threadsafe `Flag` type and waking up the event loop. The idea was to prevent unnecessary calls to the glutin window's wakeup_event_loop() method which can be expensive. This complexity made it difficult to get synchronization between the pty reader and the render thread correct. Now, the `dirty` flag on the terminal is also used to prevent spurious wakeups. It is only changed when the mutex is held, so race conditions associated with that flag shouldn't happen. --- src/event_loop.rs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'src/event_loop.rs') diff --git a/src/event_loop.rs b/src/event_loop.rs index a6eed40e..d1c52367 100644 --- a/src/event_loop.rs +++ b/src/event_loop.rs @@ -211,9 +211,14 @@ impl EventLoop state.parser.advance(&mut *terminal, *byte, &mut self.pty); } - terminal.dirty = true; - - self.display.notify(); + // Only request a draw if one hasn't already been requested. + // + // This is a performance optimization even if only for X11 + // which is very expensive to hammer on the even loop wakeup + if !terminal.dirty { + self.display.notify(); + terminal.dirty = true; + } }, Err(err) => { match err.kind() { -- cgit v1.2.3-54-g00ecf