Skip to content

Commit

Permalink
[monojob] Check for job progress only once per timer tick
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
mcb30 committed Sep 5, 2017
1 parent 97f0f56 commit 7e6b367
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions src/core/monojob.c
Expand Up @@ -64,7 +64,7 @@ struct interface monojob = INTF_INIT ( monojob_intf_desc );
*/
int monojob_wait ( const char *string, unsigned long timeout ) {
struct job_progress progress;
unsigned long last_keycheck;
unsigned long last_check;
unsigned long last_progress;
unsigned long last_display;
unsigned long now;
Expand All @@ -81,26 +81,28 @@ int monojob_wait ( const char *string, unsigned long timeout ) {
if ( string )
printf ( "%s...", string );
monojob_rc = -EINPROGRESS;
last_keycheck = last_progress = last_display = currticks();
last_check = last_progress = last_display = currticks();
while ( monojob_rc == -EINPROGRESS ) {

/* Allow job to progress */
step();
now = currticks();

/* Check for keypresses. This can be time-consuming,
* so check only once per clock tick.
/* Continue until a timer tick occurs (to minimise
* time wasted checking for progress and keypresses).
*/
elapsed = ( now - last_keycheck );
if ( elapsed ) {
if ( iskey() ) {
key = getchar();
if ( key == CTRL_C ) {
monojob_rc = -ECANCELED;
break;
}
elapsed = ( now - last_check );
if ( ! elapsed )
continue;
last_check = now;

/* Check for keypresses */
if ( iskey() ) {
key = getchar();
if ( key == CTRL_C ) {
monojob_rc = -ECANCELED;
break;
}
last_keycheck = now;
}

/* Monitor progress */
Expand Down

0 comments on commit 7e6b367

Please sign in to comment.