summaryrefslogtreecommitdiffstats
path: root/src/core
diff options
context:
space:
mode:
authorMichael Brown2017-03-27 14:31:42 +0200
committerMichael Brown2017-03-27 14:41:22 +0200
commit6bd0060f265907dc4cd687926777c19fc3c7a683 (patch)
tree47b86df501506d8d84f15506a6a1302aeabc6e98 /src/core
parent[int13con] Avoid overwriting random portions of SAN boot disks (diff)
downloadipxe-6bd0060f265907dc4cd687926777c19fc3c7a683.tar.gz
ipxe-6bd0060f265907dc4cd687926777c19fc3c7a683.tar.xz
ipxe-6bd0060f265907dc4cd687926777c19fc3c7a683.zip
[time] Add sleep_fixed() function to sleep without checking for Ctrl-C
Signed-off-by: Michael Brown <mcb30@ipxe.org>
Diffstat (limited to 'src/core')
-rw-r--r--src/core/timer.c39
1 files changed, 36 insertions, 3 deletions
diff --git a/src/core/timer.c b/src/core/timer.c
index 791cdcdb..24745cef 100644
--- a/src/core/timer.c
+++ b/src/core/timer.c
@@ -90,19 +90,21 @@ void mdelay ( unsigned long msecs ) {
}
/**
- * Sleep (interruptibly) for a fixed number of seconds
+ * Sleep (possibly interruptibly) for a fixed number of seconds
*
* @v secs Number of seconds for which to delay
+ * @v interrupted Interrupt checking method, or NULL
* @ret secs Number of seconds remaining, if interrupted
*/
-unsigned int sleep ( unsigned int secs ) {
+static unsigned int sleep_interruptible ( unsigned int secs,
+ int ( * interrupted ) ( void ) ) {
unsigned long start = currticks();
unsigned long now;
for ( ; secs ; secs-- ) {
while ( ( ( now = currticks() ) - start ) < TICKS_PER_SEC ) {
step();
- if ( iskey() && ( getchar() == CTRL_C ) )
+ if ( interrupted && interrupted() )
return secs;
cpu_nap();
}
@@ -113,6 +115,37 @@ unsigned int sleep ( unsigned int secs ) {
}
/**
+ * Check if sleep has been interrupted by keypress
+ *
+ * @ret interrupted Sleep has been interrupted
+ */
+static int keypress_interrupted ( void ) {
+
+ return ( iskey() && ( getchar() == CTRL_C ) );
+}
+
+/**
+ * Sleep (interruptibly) for a fixed number of seconds
+ *
+ * @v secs Number of seconds for which to delay
+ * @ret secs Number of seconds remaining, if interrupted
+ */
+unsigned int sleep ( unsigned int secs ) {
+
+ return sleep_interruptible ( secs, keypress_interrupted );
+}
+
+/**
+ * Sleep (uninterruptibly) for a fixed number of seconds
+ *
+ * @v secs Number of seconds for which to delay
+ */
+void sleep_fixed ( unsigned int secs ) {
+
+ sleep_interruptible ( secs, NULL );
+}
+
+/**
* Find a working timer
*
*/