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 ) {
|
int monojob_wait ( const char *string, unsigned long timeout ) {
|
||||||
struct job_progress progress;
|
struct job_progress progress;
|
||||||
unsigned long start;
|
|
||||||
unsigned long last_keycheck;
|
unsigned long last_keycheck;
|
||||||
unsigned long last_progress;
|
unsigned long last_progress;
|
||||||
|
unsigned long last_display;
|
||||||
unsigned long now;
|
unsigned long now;
|
||||||
unsigned long elapsed;
|
unsigned long elapsed;
|
||||||
unsigned long completed;
|
unsigned long completed = 0;
|
||||||
unsigned long total;
|
unsigned long scaled_completed;
|
||||||
|
unsigned long scaled_total;
|
||||||
unsigned int percentage;
|
unsigned int percentage;
|
||||||
int shown_percentage = 0;
|
int shown_percentage = 0;
|
||||||
int ongoing_rc;
|
int ongoing_rc;
|
||||||
|
@ -76,7 +77,7 @@ 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 = start = currticks();
|
last_keycheck = last_progress = last_display = currticks();
|
||||||
while ( monojob_rc == -EINPROGRESS ) {
|
while ( monojob_rc == -EINPROGRESS ) {
|
||||||
|
|
||||||
/* Allow job to progress */
|
/* Allow job to progress */
|
||||||
|
@ -101,30 +102,36 @@ int monojob_wait ( const char *string, unsigned long timeout ) {
|
||||||
/* Monitor progress */
|
/* Monitor progress */
|
||||||
ongoing_rc = job_progress ( &monojob, &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 */
|
/* Check for timeout, if applicable */
|
||||||
elapsed = ( now - start );
|
elapsed = ( now - last_progress );
|
||||||
if ( timeout && ( elapsed >= timeout ) ) {
|
if ( timeout && ( elapsed >= timeout ) ) {
|
||||||
monojob_rc = ( ongoing_rc ? ongoing_rc : -ETIMEDOUT );
|
monojob_rc = ( ongoing_rc ? ongoing_rc : -ETIMEDOUT );
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Display progress, if applicable */
|
/* Display progress, if applicable */
|
||||||
elapsed = ( now - last_progress );
|
elapsed = ( now - last_display );
|
||||||
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" );
|
||||||
/* Normalise progress figures to avoid overflow */
|
/* Normalise progress figures to avoid overflow */
|
||||||
completed = ( progress.completed / 128 );
|
scaled_completed = ( progress.completed / 128 );
|
||||||
total = ( progress.total / 128 );
|
scaled_total = ( progress.total / 128 );
|
||||||
if ( total ) {
|
if ( scaled_total ) {
|
||||||
percentage = ( ( 100 * completed ) / total );
|
percentage = ( ( 100 * scaled_completed ) /
|
||||||
|
scaled_total );
|
||||||
printf ( "%3d%%", percentage );
|
printf ( "%3d%%", percentage );
|
||||||
shown_percentage = 1;
|
shown_percentage = 1;
|
||||||
} else {
|
} else {
|
||||||
printf ( "." );
|
printf ( "." );
|
||||||
shown_percentage = 0;
|
shown_percentage = 0;
|
||||||
}
|
}
|
||||||
last_progress = now;
|
last_display = now;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
rc = monojob_rc;
|
rc = monojob_rc;
|
||||||
|
|
Loading…
Reference in New Issue