8322 nl: misleading-indentation
[unleashed/tickless.git] / usr / src / lib / libbc / libc / gen / 4.2 / sleep.c
blob4ec54f23e4e92722ed5fae124e3071909dd37a6f
1 /*
2 * copyright (c) 1980 Regents of the University of California.
3 * All rights reserved. The Berkeley software License Agreement
4 * specifies the terms and conditions for redistribution.
5 */
7 #pragma ident "%Z%%M% %I% %E% SMI"
9 #include <sys/time.h>
10 #include <signal.h>
12 #define setvec(vec, a) \
13 vec.sv_handler = a; vec.sv_mask = vec.sv_onstack = 0
15 static int ringring;
17 static void sleepx(void);
19 void
20 sleep(unsigned n)
22 int omask;
23 struct itimerval itv, oitv;
24 struct itimerval *itp = &itv;
25 struct sigvec vec, ovec;
27 if (n == 0)
28 return;
29 timerclear(&itp->it_interval);
30 timerclear(&itp->it_value);
31 if (setitimer(ITIMER_REAL, itp, &oitv) < 0)
32 return;
33 itp->it_value.tv_sec = n;
34 if (timerisset(&oitv.it_value)) {
35 if (timercmp(&oitv.it_value, &itp->it_value, >))
36 oitv.it_value.tv_sec -= itp->it_value.tv_sec;
37 else {
38 itp->it_value = oitv.it_value;
40 * This is a hack, but we must have time to
41 * return from the setitimer after the alarm
42 * or else it'll be restarted. And, anyway,
43 * sleep never did anything more than this before.
45 oitv.it_value.tv_sec = 1;
46 oitv.it_value.tv_usec = 0;
49 setvec(vec, sleepx);
50 (void) sigvec(SIGALRM, &vec, &ovec);
51 omask = sigblock(sigmask(SIGALRM));
52 ringring = 0;
53 (void) setitimer(ITIMER_REAL, itp, (struct itimerval *)0);
54 while (!ringring)
55 sigpause(omask &~ sigmask(SIGALRM));
56 (void) sigvec(SIGALRM, &ovec, (struct sigvec *)0);
57 (void) sigsetmask(omask);
58 (void) setitimer(ITIMER_REAL, &oitv, (struct itimerval *)0);
61 static void
62 sleepx(void)
65 ringring = 1;