[time] Add sleep_fixed() function to sleep without checking for Ctrl-C
Signed-off-by: Michael Brown <mcb30@ipxe.org>
This commit is contained in:
parent
c73af29fe2
commit
6bd0060f26
|
@ -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 secs Number of seconds for which to delay
|
||||||
|
* @v interrupted Interrupt checking method, or NULL
|
||||||
* @ret secs Number of seconds remaining, if interrupted
|
* @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 start = currticks();
|
||||||
unsigned long now;
|
unsigned long now;
|
||||||
|
|
||||||
for ( ; secs ; secs-- ) {
|
for ( ; secs ; secs-- ) {
|
||||||
while ( ( ( now = currticks() ) - start ) < TICKS_PER_SEC ) {
|
while ( ( ( now = currticks() ) - start ) < TICKS_PER_SEC ) {
|
||||||
step();
|
step();
|
||||||
if ( iskey() && ( getchar() == CTRL_C ) )
|
if ( interrupted && interrupted() )
|
||||||
return secs;
|
return secs;
|
||||||
cpu_nap();
|
cpu_nap();
|
||||||
}
|
}
|
||||||
|
@ -112,6 +114,37 @@ unsigned int sleep ( unsigned int secs ) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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
|
* Find a working timer
|
||||||
*
|
*
|
||||||
|
|
|
@ -75,5 +75,6 @@ extern void udelay ( unsigned long usecs );
|
||||||
extern void mdelay ( unsigned long msecs );
|
extern void mdelay ( unsigned long msecs );
|
||||||
extern unsigned long currticks ( void );
|
extern unsigned long currticks ( void );
|
||||||
extern unsigned int sleep ( unsigned int seconds );
|
extern unsigned int sleep ( unsigned int seconds );
|
||||||
|
extern void sleep_fixed ( unsigned int secs );
|
||||||
|
|
||||||
#endif /* _IPXE_TIMER_H */
|
#endif /* _IPXE_TIMER_H */
|
||||||
|
|
Reference in New Issue