summaryrefslogtreecommitdiffstats
path: root/src/core/monojob.c
diff options
context:
space:
mode:
authorMichael Brown2014-03-10 14:16:18 +0100
committerMichael Brown2014-03-10 14:16:18 +0100
commitb850a6be2811e9c21d2f6c02ed6c94c51a6522a6 (patch)
tree1c659266d7c446d35d6fb2ad481f86287cc53256 /src/core/monojob.c
parent[realtek] Dump all MII register contents when link status changes (diff)
downloadipxe-b850a6be2811e9c21d2f6c02ed6c94c51a6522a6.tar.gz
ipxe-b850a6be2811e9c21d2f6c02ed6c94c51a6522a6.tar.xz
ipxe-b850a6be2811e9c21d2f6c02ed6c94c51a6522a6.zip
[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>
Diffstat (limited to 'src/core/monojob.c')
-rw-r--r--src/core/monojob.c29
1 files changed, 18 insertions, 11 deletions
diff --git a/src/core/monojob.c b/src/core/monojob.c
index 5dbfa406..820fa31d 100644
--- a/src/core/monojob.c
+++ b/src/core/monojob.c
@@ -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;