mirror of https://github.com/ipxe/ipxe.git
[monojob] Reset timeout when progress is made
Redefine the timeout parameter from "time since start of job" to "time since progress was last made". This does not affect any existing behaviour, since all existing users of the timeout parameter do not provide progress indication. Signed-off-by: Michael Brown <mcb30@ipxe.org>pull/17/head
parent
145fc26ed5
commit
b850a6be28
|
@ -60,13 +60,14 @@ struct interface monojob = INTF_INIT ( monojob_intf_desc );
|
|||
*/
|
||||
int monojob_wait ( const char *string, unsigned long timeout ) {
|
||||
struct job_progress progress;
|
||||
unsigned long start;
|
||||
unsigned long last_keycheck;
|
||||
unsigned long last_progress;
|
||||
unsigned long last_display;
|
||||
unsigned long now;
|
||||
unsigned long elapsed;
|
||||
unsigned long completed;
|
||||
unsigned long total;
|
||||
unsigned long completed = 0;
|
||||
unsigned long scaled_completed;
|
||||
unsigned long scaled_total;
|
||||
unsigned int percentage;
|
||||
int shown_percentage = 0;
|
||||
int ongoing_rc;
|
||||
|
@ -76,7 +77,7 @@ int monojob_wait ( const char *string, unsigned long timeout ) {
|
|||
if ( string )
|
||||
printf ( "%s...", string );
|
||||
monojob_rc = -EINPROGRESS;
|
||||
last_keycheck = last_progress = start = currticks();
|
||||
last_keycheck = last_progress = last_display = currticks();
|
||||
while ( monojob_rc == -EINPROGRESS ) {
|
||||
|
||||
/* Allow job to progress */
|
||||
|
@ -101,30 +102,36 @@ int monojob_wait ( const char *string, unsigned long timeout ) {
|
|||
/* Monitor progress */
|
||||
ongoing_rc = job_progress ( &monojob, &progress );
|
||||
|
||||
/* Reset timeout if progress has been made */
|
||||
if ( completed != progress.completed )
|
||||
last_progress = now;
|
||||
completed = progress.completed;
|
||||
|
||||
/* Check for timeout, if applicable */
|
||||
elapsed = ( now - start );
|
||||
elapsed = ( now - last_progress );
|
||||
if ( timeout && ( elapsed >= timeout ) ) {
|
||||
monojob_rc = ( ongoing_rc ? ongoing_rc : -ETIMEDOUT );
|
||||
break;
|
||||
}
|
||||
|
||||
/* Display progress, if applicable */
|
||||
elapsed = ( now - last_progress );
|
||||
elapsed = ( now - last_display );
|
||||
if ( string && ( elapsed >= TICKS_PER_SEC ) ) {
|
||||
if ( shown_percentage )
|
||||
printf ( "\b\b\b\b \b\b\b\b" );
|
||||
/* Normalise progress figures to avoid overflow */
|
||||
completed = ( progress.completed / 128 );
|
||||
total = ( progress.total / 128 );
|
||||
if ( total ) {
|
||||
percentage = ( ( 100 * completed ) / total );
|
||||
scaled_completed = ( progress.completed / 128 );
|
||||
scaled_total = ( progress.total / 128 );
|
||||
if ( scaled_total ) {
|
||||
percentage = ( ( 100 * scaled_completed ) /
|
||||
scaled_total );
|
||||
printf ( "%3d%%", percentage );
|
||||
shown_percentage = 1;
|
||||
} else {
|
||||
printf ( "." );
|
||||
shown_percentage = 0;
|
||||
}
|
||||
last_progress = now;
|
||||
last_display = now;
|
||||
}
|
||||
}
|
||||
rc = monojob_rc;
|
||||
|
|
Loading…
Reference in New Issue