ack/lang/cem/libcc/gen/sleep.c

40 lines
676 B
C
Raw Normal View History

1987-03-31 10:45:53 +00:00
/* $Header$ */
1987-01-27 15:57:55 +00:00
#include <signal.h>
#include <setjmp.h>
static jmp_buf setjmpbuf;
static
alfun(){
longjmp(setjmpbuf, 1);
} /* used with sleep() below */
sleep(n)
int n;
{
/* sleep(n) pauses for 'n' seconds by scheduling an alarm interrupt. */
unsigned oldalarm;
int (*oldsig)();
if (n <= 0) return;
if (setjmp(setjmpbuf)) {
signal(SIGALRM, oldsig);
alarm(oldalarm);
return;
}
oldalarm = alarm(5000); /* Who cares how long, as long as it is long
enough
*/
if (oldalarm > n) oldalarm -= n;
else {
n = oldalarm;
oldalarm = 1;
}
oldsig = signal(SIGALRM, alfun);
alarm(n);
for (;;) {
/* allow for other handlers ... */
pause();
}
}