mirror of https://github.com/ipxe/ipxe.git
[libc] Make sleep() interruptible
Signed-off-by: Michael Brown <mcb30@ipxe.org>pull/51/head
parent
860d5904fb
commit
ee3122bc54
|
@ -36,10 +36,6 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
|
||||||
#include <ipxe/command.h>
|
#include <ipxe/command.h>
|
||||||
#include <ipxe/parseopt.h>
|
#include <ipxe/parseopt.h>
|
||||||
#include <ipxe/settings.h>
|
#include <ipxe/settings.h>
|
||||||
#include <ipxe/console.h>
|
|
||||||
#include <ipxe/keys.h>
|
|
||||||
#include <ipxe/process.h>
|
|
||||||
#include <ipxe/nap.h>
|
|
||||||
#include <ipxe/shell.h>
|
#include <ipxe/shell.h>
|
||||||
|
|
||||||
/** @file
|
/** @file
|
||||||
|
@ -573,8 +569,6 @@ static struct command_descriptor sleep_cmd =
|
||||||
static int sleep_exec ( int argc, char **argv ) {
|
static int sleep_exec ( int argc, char **argv ) {
|
||||||
struct sleep_options opts;
|
struct sleep_options opts;
|
||||||
unsigned int seconds;
|
unsigned int seconds;
|
||||||
unsigned long start;
|
|
||||||
unsigned long delay;
|
|
||||||
int rc;
|
int rc;
|
||||||
|
|
||||||
/* Parse options */
|
/* Parse options */
|
||||||
|
@ -586,14 +580,8 @@ static int sleep_exec ( int argc, char **argv ) {
|
||||||
return rc;
|
return rc;
|
||||||
|
|
||||||
/* Delay for specified number of seconds */
|
/* Delay for specified number of seconds */
|
||||||
start = currticks();
|
if ( sleep ( seconds ) != 0 )
|
||||||
delay = ( seconds * TICKS_PER_SEC );
|
|
||||||
while ( ( currticks() - start ) <= delay ) {
|
|
||||||
step();
|
|
||||||
if ( iskey() && ( getchar() == CTRL_C ) )
|
|
||||||
return -ECANCELED;
|
return -ECANCELED;
|
||||||
cpu_nap();
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,6 +24,10 @@
|
||||||
FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
|
FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
|
||||||
|
|
||||||
#include <unistd.h>
|
#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
|
* 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
|
* @v secs Number of seconds for which to delay
|
||||||
|
* @ret secs Number of seconds remaining, if interrupted
|
||||||
*/
|
*/
|
||||||
unsigned int sleep ( unsigned int secs ) {
|
unsigned int sleep ( unsigned int secs ) {
|
||||||
while ( secs-- )
|
unsigned long start = currticks();
|
||||||
mdelay ( 1000 );
|
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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue