Utah Raster Toolkit  9999-git
URT Development version (post-3.1b)
timer.c
Go to the documentation of this file.
1 /*
2  * This software is copyrighted as noted below. It may be freely copied,
3  * modified, and redistributed, provided that the copyright notice is
4  * preserved on all copies.
5  *
6  * There is no warranty or other guarantee of fitness for this software,
7  * it is provided solely "as is". Bug reports or fixes may be sent
8  * to the author, who may or may not act on them as he desires.
9  *
10  * You may not include this software in a program or other software product
11  * without supplying the source, or without informing the end-user that the
12  * source is available for no extra charge.
13  *
14  * If you modify this software, you should include a notice giving the
15  * name of the person performing the modification, the date of modification,
16  * and the reason for such modification.
17  */
18 
19 /* Copyright 1990,1992 The Regents of the University of Michigan */
20 
21 #ifndef lint
22 static char rcsid[] = "$Header: /l/spencer/src/urt/get/getx11/RCS/timer.c,v 3.0.1.3 1992/03/04 19:31:40 spencer Exp $";
23 #endif
24 
25 #include <stdlib.h>
26 #include <string.h>
27 #include <signal.h>
28 #include <sys/time.h>
29 #include "rle_config.h"
30 
31 #define USPS 1000000 /* number of microseconds in a second */
32 #define TICK 10000 /* system clock resolution in microseconds */
33 
34 #ifndef NO_ITIMER
35 static int ringring;
36 static void (*ofunc)();
37 
38 static void
39 sleepx()
40 {
41  ringring = 1;
42 }
43 #endif
44 
45 void
47 unsigned n;
48 {
49 #ifndef NO_ITIMER
50  struct itimerval itv;
51  register struct itimerval *itp = &itv;
52  if (n == 0)
53  {
54  ringring = 1;
55  return;
56  }
57  timerclear(&itp->it_interval);
58  itp->it_value.tv_sec = n / USPS;
59  itp->it_value.tv_usec = n % USPS;
60  ofunc = (void (*)())signal(SIGALRM, sleepx);
61 
62  ringring = 0;
63  (void) setitimer(ITIMER_REAL, itp, (struct itimerval *)0);
64 #endif
65 }
66 
67 #ifndef sigmask
68 #define sigmask(m) (1 << ((m)-1))
69 #endif
70 
71 void
73 {
74 #ifndef NO_ITIMER
75  while (!ringring)
76  sigpause( ~sigmask(SIGALRM));
77  signal(SIGALRM, ofunc);
78 #endif
79 }
static void(* ofunc)()
Definition: timer.c:36
static char rcsid[]
Definition: timer.c:22
#define USPS
Definition: timer.c:31
void wait_timer(void)
Definition: timer.c:72
void set_timer(unsigned n)
Definition: timer.c:46
static int ringring
Definition: timer.c:35