[monojob] Check for keypresses only once per timer tick
Checking for keypresses takes a non-negligible amount of time, and measurably affects our RTT. Minimise the impact by checking for keypresses only once per timer tick. Signed-off-by: Michael Brown <mcb30@ipxe.org>
This commit is contained in:
parent
ec22e08db1
commit
85917ba8dd
|
@ -60,7 +60,9 @@ int monojob_wait ( const char *string ) {
|
||||||
struct job_progress progress;
|
struct job_progress progress;
|
||||||
int key;
|
int key;
|
||||||
int rc;
|
int rc;
|
||||||
|
unsigned long last_keycheck;
|
||||||
unsigned long last_progress;
|
unsigned long last_progress;
|
||||||
|
unsigned long now;
|
||||||
unsigned long elapsed;
|
unsigned long elapsed;
|
||||||
unsigned long completed;
|
unsigned long completed;
|
||||||
unsigned long total;
|
unsigned long total;
|
||||||
|
@ -70,20 +72,32 @@ int monojob_wait ( const char *string ) {
|
||||||
if ( string )
|
if ( string )
|
||||||
printf ( "%s...", string );
|
printf ( "%s...", string );
|
||||||
monojob_rc = -EINPROGRESS;
|
monojob_rc = -EINPROGRESS;
|
||||||
last_progress = currticks();
|
last_keycheck = last_progress = currticks();
|
||||||
while ( monojob_rc == -EINPROGRESS ) {
|
while ( monojob_rc == -EINPROGRESS ) {
|
||||||
|
|
||||||
|
/* Allow job to progress */
|
||||||
step();
|
step();
|
||||||
if ( iskey() ) {
|
now = currticks();
|
||||||
key = getchar();
|
|
||||||
switch ( key ) {
|
/* Check for keypresses. This can be time-consuming,
|
||||||
case CTRL_C:
|
* so check only once per clock tick.
|
||||||
monojob_close ( &monojob, -ECANCELED );
|
*/
|
||||||
break;
|
if ( now != last_keycheck ) {
|
||||||
default:
|
if ( iskey() ) {
|
||||||
break;
|
key = getchar();
|
||||||
|
switch ( key ) {
|
||||||
|
case CTRL_C:
|
||||||
|
monojob_close ( &monojob, -ECANCELED );
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
last_keycheck = now;
|
||||||
}
|
}
|
||||||
elapsed = ( currticks() - last_progress );
|
|
||||||
|
/* Display progress, if applicable */
|
||||||
|
elapsed = ( now - last_progress );
|
||||||
if ( string && ( elapsed >= TICKS_PER_SEC ) ) {
|
if ( string && ( elapsed >= TICKS_PER_SEC ) ) {
|
||||||
if ( shown_percentage )
|
if ( shown_percentage )
|
||||||
printf ( "\b\b\b\b \b\b\b\b" );
|
printf ( "\b\b\b\b \b\b\b\b" );
|
||||||
|
@ -99,7 +113,7 @@ int monojob_wait ( const char *string ) {
|
||||||
printf ( "." );
|
printf ( "." );
|
||||||
shown_percentage = 0;
|
shown_percentage = 0;
|
||||||
}
|
}
|
||||||
last_progress = currticks();
|
last_progress = now;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
rc = monojob_rc;
|
rc = monojob_rc;
|
||||||
|
|
Reference in New Issue