home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / general / procssng / ccs / ccs-11tl.lha / lbl / x11 / lib / timer.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-05-31  |  870 b   |  48 lines

  1. #include <stdio.h>
  2. #include <signal.h>
  3. #include <sys/time.h>
  4.  
  5. #define USPS    1000000         /* number of microseconds in a second */
  6. #define TICK    10000           /* system clock resolution in microseconds */
  7.  
  8. static int ringring;
  9. static void (*ofunc)();
  10.     
  11. static void
  12. sleepx()
  13. {
  14.         ringring = 1;
  15. }
  16.  
  17. void
  18. set_timer(n)
  19. unsigned n;
  20. {
  21.     struct itimerval itv;
  22.     register struct itimerval *itp = &itv;
  23.     if (n == 0)
  24.     {
  25.     ringring = 1;
  26.     return;
  27.     }
  28.     timerclear(&itp->it_interval);
  29.     itp->it_value.tv_sec = n / USPS;
  30.     itp->it_value.tv_usec = n % USPS;
  31.     ofunc = (void (*)())signal(SIGALRM, sleepx);
  32.  
  33.     ringring = 0;
  34.     (void) setitimer(ITIMER_REAL, itp, (struct itimerval *)0);
  35. }
  36.  
  37. #ifndef sigmask
  38. #define sigmask(m)    (1 << ((m)-1))
  39. #endif
  40.  
  41. void
  42. wait_timer()
  43. {
  44.     while (!ringring)
  45.     sigpause( ~sigmask(SIGALRM));
  46.     signal(SIGALRM, ofunc);
  47. }
  48.