summaryrefslogtreecommitdiffstats
path: root/src/core/monojob.c
diff options
context:
space:
mode:
authorMichael Brown2012-06-28 13:27:43 +0200
committerMichael Brown2012-06-28 17:02:37 +0200
commit85917ba8dd7814856be12f8c00ef755547166fad (patch)
tree8550cbc5c652eef87ce59d85ad60691c58e6fd7e /src/core/monojob.c
parent[tcpip] Add faster algorithm for calculating the TCP/IP checksum (diff)
downloadipxe-85917ba8dd7814856be12f8c00ef755547166fad.tar.gz
ipxe-85917ba8dd7814856be12f8c00ef755547166fad.tar.xz
ipxe-85917ba8dd7814856be12f8c00ef755547166fad.zip
[monojob] Check for keypresses only once per timer tick
Checking for keypresses takes a non-negligible amount of time, and measurably affects our RTT. Minimise the impact by checking for keypresses only once per timer tick. Signed-off-by: Michael Brown <mcb30@ipxe.org>
Diffstat (limited to 'src/core/monojob.c')
-rw-r--r--src/core/monojob.c36
1 files changed, 25 insertions, 11 deletions
diff --git a/src/core/monojob.c b/src/core/monojob.c
index 7917b427..d2161b3c 100644
--- a/src/core/monojob.c
+++ b/src/core/monojob.c
@@ -60,7 +60,9 @@ int monojob_wait ( const char *string ) {
struct job_progress progress;
int key;
int rc;
+ unsigned long last_keycheck;
unsigned long last_progress;
+ unsigned long now;
unsigned long elapsed;
unsigned long completed;
unsigned long total;
@@ -70,20 +72,32 @@ int monojob_wait ( const char *string ) {
if ( string )
printf ( "%s...", string );
monojob_rc = -EINPROGRESS;
- last_progress = currticks();
+ last_keycheck = last_progress = currticks();
while ( monojob_rc == -EINPROGRESS ) {
+
+ /* Allow job to progress */
step();
- if ( iskey() ) {
- key = getchar();
- switch ( key ) {
- case CTRL_C:
- monojob_close ( &monojob, -ECANCELED );
- break;
- default:
- break;
+ now = currticks();
+
+ /* Check for keypresses. This can be time-consuming,
+ * so check only once per clock tick.
+ */
+ if ( now != last_keycheck ) {
+ if ( iskey() ) {
+ key = getchar();
+ switch ( key ) {
+ case CTRL_C:
+ monojob_close ( &monojob, -ECANCELED );
+ break;
+ default:
+ break;
+ }
}
+ last_keycheck = now;
}
- elapsed = ( currticks() - last_progress );
+
+ /* Display progress, if applicable */
+ elapsed = ( now - last_progress );
if ( string && ( elapsed >= TICKS_PER_SEC ) ) {
if ( shown_percentage )
printf ( "\b\b\b\b \b\b\b\b" );
@@ -99,7 +113,7 @@ int monojob_wait ( const char *string ) {
printf ( "." );
shown_percentage = 0;
}
- last_progress = currticks();
+ last_progress = now;
}
}
rc = monojob_rc;