2 * Copyright 1996 Sun Microsystems, Inc. All rights reserved.
3 * Use is subject to license terms.
7 * Copyright (c) 1985 Regents of the University of California.
8 * All rights reserved. The Berkeley software License Agreement
9 * specifies the terms and conditions for redistribution.
16 #define USPS 1000000 /* number of microseconds in a second */
17 #define TICK (USPS / _sysconf(_SC_CLK_TCK))
19 #define setvec(vec, a) \
20 vec.sv_handler = a; vec.sv_mask = vec.sv_onstack = 0
35 struct itimerval itv
, oitv
;
36 struct itimerval
*itp
= &itv
;
37 struct sigvec vec
, ovec
;
41 timerclear(&itp
->it_interval
);
42 timerclear(&itp
->it_value
);
43 if (setitimer(ITIMER_REAL
, itp
, &oitv
) < 0)
45 itp
->it_value
.tv_sec
= n
/ USPS
;
46 itp
->it_value
.tv_usec
= n
% USPS
;
47 if (timerisset(&oitv
.it_value
)) {
48 if (timercmp(&oitv
.it_value
, &itp
->it_value
, >)) {
49 oitv
.it_value
.tv_sec
-= itp
->it_value
.tv_sec
;
50 oitv
.it_value
.tv_usec
-= itp
->it_value
.tv_usec
;
51 if (oitv
.it_value
.tv_usec
< 0) {
52 oitv
.it_value
.tv_usec
+= USPS
;
53 oitv
.it_value
.tv_sec
--;
56 itp
->it_value
= oitv
.it_value
;
57 oitv
.it_value
.tv_sec
= 0;
58 oitv
.it_value
.tv_usec
= 2 * TICK
;
62 (void) sigvec(SIGALRM
, &vec
, &ovec
);
63 omask
= sigblock(sigmask(SIGALRM
));
65 (void) setitimer(ITIMER_REAL
, itp
, (struct itimerval
*)0);
67 sigpause(omask
&~ sigmask(SIGALRM
));
68 (void) sigvec(SIGALRM
, &ovec
, (struct sigvec
*)0);
69 (void) sigsetmask(omask
);
70 (void) setitimer(ITIMER_REAL
, &oitv
, (struct itimerval
*)0);