]>
git.cameronkatri.com Git - bsdgames-darwin.git/blob - larn/nap.c
2 static char rcsid
[] = "$Id: nap.c,v 1.2 1993/08/02 17:20:15 mycroft Exp $";
5 /* nap.c Larn is copyrighted 1986 by Noah Morgan. */
12 #include <sys/timeb.h>
17 * routine to take a nap for n milliseconds
22 if (x
<=0) return; /* eliminate chance for infinite loop */
24 if (x
> 999) sleep(x
/1000); else napms(x
);
28 napms(x
) /* do nothing */
34 /* napms - sleep for time milliseconds - uses times() */
35 /* this assumes that times returns a relative time in 60ths of a second */
36 /* this will do horrible things if your times() returns seconds! */
40 long matchclock
, times();
43 if (time
<=0) time
=1; /* eliminate chance for infinite loop */
44 if ((matchclock
= times(&stats
)) == -1 || matchclock
== 0)
45 return; /* error, or BSD style times() */
46 matchclock
+= (time
/ 17); /*17 ms/tic is 1000 ms/sec / 60 tics/sec */
48 while(matchclock
< times(&stats
))
55 /* This must be BSD 4.2! */
57 #define bit(_a) (1<<((_a)-1))
63 /* napms - sleep for time milliseconds - uses setitimer() */
67 struct itimerval timeout
;
71 if (time
<= 0) return;
73 timerclear(&timeout
.it_interval
);
74 timeout
.it_value
.tv_sec
= time
/ 1000;
75 timeout
.it_value
.tv_usec
= (time
% 1000) * 1000;
77 oldsig
= sigblock(bit(SIGALRM
));
78 setitimer(ITIMER_REAL
, &timeout
, (struct itimerval
*)0);
79 oldhandler
= signal(SIGALRM
, nullf
);
81 signal(SIGALRM
, oldhandler
);
86 /* napms - sleep for time milliseconds - uses ftime() */
91 /* assumed to be BSD UNIX */
94 unsigned short matchmilli
;
95 register struct timeb
*tp
= & _gtime
;
97 if (time
<= 0) return;
99 matchmilli
= tp
->millitm
+ time
;
100 matchtime
= tp
->time
;
101 while (matchmilli
>= 1000)
110 if ((tp
->time
> matchtime
) ||
111 ((tp
->time
== matchtime
) && (tp
->millitm
>= matchmilli
)))
117 static napms(time
) int time
; {} /* do nothing, forget it */