david/ipxe
david
/
ipxe
Archived
1
0
Fork 0

[monojob] Check for job progress only once per timer tick

Checking for job progress is essentially a user interface activity,
and can safely be performed only once per timer tick (as is already
done with checking for keypresses).

Signed-off-by: Michael Brown <mcb30@ipxe.org>
This commit is contained in:
Michael Brown 2017-09-05 23:21:34 +01:00
parent 97f0f56a34
commit 7e6b367b7e
1 changed files with 15 additions and 13 deletions

View File

@ -64,7 +64,7 @@ struct interface monojob = INTF_INIT ( monojob_intf_desc );
*/ */
int monojob_wait ( const char *string, unsigned long timeout ) { int monojob_wait ( const char *string, unsigned long timeout ) {
struct job_progress progress; struct job_progress progress;
unsigned long last_keycheck; unsigned long last_check;
unsigned long last_progress; unsigned long last_progress;
unsigned long last_display; unsigned long last_display;
unsigned long now; unsigned long now;
@ -81,26 +81,28 @@ int monojob_wait ( const char *string, unsigned long timeout ) {
if ( string ) if ( string )
printf ( "%s...", string ); printf ( "%s...", string );
monojob_rc = -EINPROGRESS; monojob_rc = -EINPROGRESS;
last_keycheck = last_progress = last_display = currticks(); last_check = last_progress = last_display = currticks();
while ( monojob_rc == -EINPROGRESS ) { while ( monojob_rc == -EINPROGRESS ) {
/* Allow job to progress */ /* Allow job to progress */
step(); step();
now = currticks(); now = currticks();
/* Check for keypresses. This can be time-consuming, /* Continue until a timer tick occurs (to minimise
* so check only once per clock tick. * time wasted checking for progress and keypresses).
*/ */
elapsed = ( now - last_keycheck ); elapsed = ( now - last_check );
if ( elapsed ) { if ( ! elapsed )
if ( iskey() ) { continue;
key = getchar(); last_check = now;
if ( key == CTRL_C ) {
monojob_rc = -ECANCELED; /* Check for keypresses */
break; if ( iskey() ) {
} key = getchar();
if ( key == CTRL_C ) {
monojob_rc = -ECANCELED;
break;
} }
last_keycheck = now;
} }
/* Monitor progress */ /* Monitor progress */