|
@@ -60,13 +60,14 @@ struct interface monojob = INTF_INIT ( monojob_intf_desc );
|
60
|
60
|
*/
|
61
|
61
|
int monojob_wait ( const char *string, unsigned long timeout ) {
|
62
|
62
|
struct job_progress progress;
|
63
|
|
- unsigned long start;
|
64
|
63
|
unsigned long last_keycheck;
|
65
|
64
|
unsigned long last_progress;
|
|
65
|
+ unsigned long last_display;
|
66
|
66
|
unsigned long now;
|
67
|
67
|
unsigned long elapsed;
|
68
|
|
- unsigned long completed;
|
69
|
|
- unsigned long total;
|
|
68
|
+ unsigned long completed = 0;
|
|
69
|
+ unsigned long scaled_completed;
|
|
70
|
+ unsigned long scaled_total;
|
70
|
71
|
unsigned int percentage;
|
71
|
72
|
int shown_percentage = 0;
|
72
|
73
|
int ongoing_rc;
|
|
@@ -76,7 +77,7 @@ int monojob_wait ( const char *string, unsigned long timeout ) {
|
76
|
77
|
if ( string )
|
77
|
78
|
printf ( "%s...", string );
|
78
|
79
|
monojob_rc = -EINPROGRESS;
|
79
|
|
- last_keycheck = last_progress = start = currticks();
|
|
80
|
+ last_keycheck = last_progress = last_display = currticks();
|
80
|
81
|
while ( monojob_rc == -EINPROGRESS ) {
|
81
|
82
|
|
82
|
83
|
/* Allow job to progress */
|
|
@@ -101,30 +102,36 @@ int monojob_wait ( const char *string, unsigned long timeout ) {
|
101
|
102
|
/* Monitor progress */
|
102
|
103
|
ongoing_rc = job_progress ( &monojob, &progress );
|
103
|
104
|
|
|
105
|
+ /* Reset timeout if progress has been made */
|
|
106
|
+ if ( completed != progress.completed )
|
|
107
|
+ last_progress = now;
|
|
108
|
+ completed = progress.completed;
|
|
109
|
+
|
104
|
110
|
/* Check for timeout, if applicable */
|
105
|
|
- elapsed = ( now - start );
|
|
111
|
+ elapsed = ( now - last_progress );
|
106
|
112
|
if ( timeout && ( elapsed >= timeout ) ) {
|
107
|
113
|
monojob_rc = ( ongoing_rc ? ongoing_rc : -ETIMEDOUT );
|
108
|
114
|
break;
|
109
|
115
|
}
|
110
|
116
|
|
111
|
117
|
/* Display progress, if applicable */
|
112
|
|
- elapsed = ( now - last_progress );
|
|
118
|
+ elapsed = ( now - last_display );
|
113
|
119
|
if ( string && ( elapsed >= TICKS_PER_SEC ) ) {
|
114
|
120
|
if ( shown_percentage )
|
115
|
121
|
printf ( "\b\b\b\b \b\b\b\b" );
|
116
|
122
|
/* Normalise progress figures to avoid overflow */
|
117
|
|
- completed = ( progress.completed / 128 );
|
118
|
|
- total = ( progress.total / 128 );
|
119
|
|
- if ( total ) {
|
120
|
|
- percentage = ( ( 100 * completed ) / total );
|
|
123
|
+ scaled_completed = ( progress.completed / 128 );
|
|
124
|
+ scaled_total = ( progress.total / 128 );
|
|
125
|
+ if ( scaled_total ) {
|
|
126
|
+ percentage = ( ( 100 * scaled_completed ) /
|
|
127
|
+ scaled_total );
|
121
|
128
|
printf ( "%3d%%", percentage );
|
122
|
129
|
shown_percentage = 1;
|
123
|
130
|
} else {
|
124
|
131
|
printf ( "." );
|
125
|
132
|
shown_percentage = 0;
|
126
|
133
|
}
|
127
|
|
- last_progress = now;
|
|
134
|
+ last_display = now;
|
128
|
135
|
}
|
129
|
136
|
}
|
130
|
137
|
rc = monojob_rc;
|