Smarter poll interval

This commit is contained in:
Keith Winstein
2011-02-06 01:48:57 -05:00
parent fd0a2f06ae
commit 1b48d7f0c9
+13 -3
View File
@@ -135,7 +135,7 @@ int main( int argc, char *argv[] )
return 0; return 0;
} }
void tick( Terminal::Emulator *e ) bool tick( Terminal::Emulator *e )
{ {
static bool initialized = false; static bool initialized = false;
static struct timeval last_time; static struct timeval last_time;
@@ -155,7 +155,11 @@ void tick( Terminal::Emulator *e )
swrite( STDOUT_FILENO, update.c_str() ); swrite( STDOUT_FILENO, update.c_str() );
initialized = true; initialized = true;
last_time = this_time; last_time = this_time;
return true;
} }
return false;
} }
void emulate_terminal( int fd, int debug_fd ) void emulate_terminal( int fd, int debug_fd )
@@ -204,8 +208,10 @@ void emulate_terminal( int fd, int debug_fd )
swrite( STDOUT_FILENO, terminal.open().c_str() ); swrite( STDOUT_FILENO, terminal.open().c_str() );
int poll_timeout = -1;
while ( 1 ) { while ( 1 ) {
int active_fds = poll( pollfds, 3, 0.02 ); int active_fds = poll( pollfds, 3, poll_timeout );
if ( active_fds < 0 ) { if ( active_fds < 0 ) {
perror( "poll" ); perror( "poll" );
break; break;
@@ -245,7 +251,11 @@ void emulate_terminal( int fd, int debug_fd )
break; break;
} }
tick( &terminal ); if ( tick( &terminal ) ) { /* there was a frame */
poll_timeout = -1;
} else {
poll_timeout = 20;
}
} }
std::string update = terminal.new_frame(); std::string update = terminal.new_frame();