mirror of
https://github.com/ipxe/ipxe
synced 2026-02-11 22:00:06 +03:00
[libc] Make sleep() interruptible
Signed-off-by: Michael Brown <mcb30@ipxe.org>
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user