Переглянути джерело

[monojob] Check for job progress only once per timer tick

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>
tags/v1.20.1
Michael Brown 6 роки тому
джерело
коміт
7e6b367b7e
1 змінених файлів з 15 додано та 13 видалено
  1. 15
    13
      src/core/monojob.c

+ 15
- 13
src/core/monojob.c Переглянути файл

64
  */
64
  */
65
 int monojob_wait ( const char *string, unsigned long timeout ) {
65
 int monojob_wait ( const char *string, unsigned long timeout ) {
66
 	struct job_progress progress;
66
 	struct job_progress progress;
67
-	unsigned long last_keycheck;
67
+	unsigned long last_check;
68
 	unsigned long last_progress;
68
 	unsigned long last_progress;
69
 	unsigned long last_display;
69
 	unsigned long last_display;
70
 	unsigned long now;
70
 	unsigned long now;
81
 	if ( string )
81
 	if ( string )
82
 		printf ( "%s...", string );
82
 		printf ( "%s...", string );
83
 	monojob_rc = -EINPROGRESS;
83
 	monojob_rc = -EINPROGRESS;
84
-	last_keycheck = last_progress = last_display = currticks();
84
+	last_check = last_progress = last_display = currticks();
85
 	while ( monojob_rc == -EINPROGRESS ) {
85
 	while ( monojob_rc == -EINPROGRESS ) {
86
 
86
 
87
 		/* Allow job to progress */
87
 		/* Allow job to progress */
88
 		step();
88
 		step();
89
 		now = currticks();
89
 		now = currticks();
90
 
90
 
91
-		/* Check for keypresses.  This can be time-consuming,
92
-		 * so check only once per clock tick.
91
+		/* Continue until a timer tick occurs (to minimise
92
+		 * time wasted checking for progress and keypresses).
93
 		 */
93
 		 */
94
-		elapsed = ( now - last_keycheck );
95
-		if ( elapsed ) {
96
-			if ( iskey() ) {
97
-				key = getchar();
98
-				if ( key == CTRL_C ) {
99
-					monojob_rc = -ECANCELED;
100
-					break;
101
-				}
94
+		elapsed = ( now - last_check );
95
+		if ( ! elapsed )
96
+			continue;
97
+		last_check = now;
98
+
99
+		/* Check for keypresses */
100
+		if ( iskey() ) {
101
+			key = getchar();
102
+			if ( key == CTRL_C ) {
103
+				monojob_rc = -ECANCELED;
104
+				break;
102
 			}
105
 			}
103
-			last_keycheck = now;
104
 		}
106
 		}
105
 
107
 
106
 		/* Monitor progress */
108
 		/* Monitor progress */

Завантаження…
Відмінити
Зберегти