diff options
author | Michael Brown | 2016-03-22 17:12:32 +0100 |
---|---|---|
committer | Michael Brown | 2016-03-22 17:18:42 +0100 |
commit | ee3122bc54631711e192c934734f3f5be40c2fa9 (patch) | |
tree | 8982b34b6c23595ed57398b6247de57b01899dff /src/core/timer.c | |
parent | [arbel] Fix received packet length (diff) | |
download | ipxe-ee3122bc54631711e192c934734f3f5be40c2fa9.tar.gz ipxe-ee3122bc54631711e192c934734f3f5be40c2fa9.tar.xz ipxe-ee3122bc54631711e192c934734f3f5be40c2fa9.zip |
[libc] Make sleep() interruptible
Signed-off-by: Michael Brown <mcb30@ipxe.org>
Diffstat (limited to 'src/core/timer.c')
-rw-r--r-- | src/core/timer.c | 22 |
1 files changed, 19 insertions, 3 deletions
diff --git a/src/core/timer.c b/src/core/timer.c index dbd89f12..ca945cfb 100644 --- a/src/core/timer.c +++ b/src/core/timer.c @@ -24,6 +24,10 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); #include <unistd.h> +#include <ipxe/process.h> +#include <ipxe/console.h> +#include <ipxe/keys.h> +#include <ipxe/nap.h> /** * Delay for a fixed number of milliseconds @@ -36,12 +40,24 @@ void mdelay ( unsigned long msecs ) { } /** - * Delay for a fixed number of seconds + * 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 ) { - while ( secs-- ) - mdelay ( 1000 ); + unsigned long start = currticks(); + unsigned long now; + + for ( ; secs ; secs-- ) { + while ( ( ( now = currticks() ) - start ) < TICKS_PER_SEC ) { + step(); + if ( iskey() && ( getchar() == CTRL_C ) ) + return secs; + cpu_nap(); + } + start = now; + } + return 0; } |