home *** CD-ROM | disk | FTP | other *** search
/ nisttime.carsoncity.k12.mi.us / nisttime.carsoncity.k12.mi.us.tar / nisttime.carsoncity.k12.mi.us / pub / lockclock / wait_l.c < prev    next >
C/C++ Source or Header  |  1996-11-18  |  1KB  |  70 lines

  1. void wait1s()
  2. {
  3. /*
  4.         this subroutine delays by 1 second each time
  5.         it is called.  the delay is only approximate and
  6.         is in fact 18 ticks of the clock for an IBMPC.  for
  7.     a SUN version, the program waits until the low part
  8.     of the time wraps around to the same value again
  9. */
  10. #include "getdif.h"
  11. #include <stdio.h>
  12. #ifdef IBMPC
  13. #include <dos.h>
  14. #endif
  15. #ifdef SUN
  16. #include <sys/time.h>
  17. struct timeval tvv,*tp;
  18. LONG old,dly;
  19. #endif
  20. int j;
  21. int k,kk;
  22. /*
  23.         get current hundredths of time for IBMPC or current
  24.     microseconds for sun
  25. */
  26. #ifdef IBMPC
  27.         _AH=0x2c;
  28.         geninterrupt(0x21);
  29.         k=_DL;
  30. #endif
  31. #ifdef SUN
  32.     tp= &tvv;
  33.     gettimeofday(tp,0);
  34.     old=tp->tv_usec;
  35. #endif
  36. #ifdef IBMPC
  37. /*
  38.     for IBMPC version, wait until tick changes 18 times --
  39.     that is approximately 1 second, although the change
  40.     of the first tick is likely to happen too soon and
  41.     the number of ticks/sec is slightly more than 18 --
  42.     both of these will cause the delay to be a bit too
  43.     short.
  44. */
  45.         for(j=0; j<18; j++)
  46.         {
  47.         do
  48.         {
  49.         _AH=0x2c;
  50.         geninterrupt(0x21);
  51.         kk=_DL;
  52.         } while (kk == k);
  53.         k=kk;
  54.         }
  55. #endif
  56. #ifdef SUN
  57. /*
  58.     for SUN version, wait until new value of microseconds is
  59.     just slightly less than old value.
  60. */
  61.     do
  62.     {
  63.     gettimeofday(tp,0);
  64.     dly=tp->tv_usec - old;
  65.     if(dly < 0) dly += 1000000;
  66.     for(k=0; k<20; k++)  ;   /* wait a bit */
  67.     } while (dly <= 970000);
  68. #endif
  69. }
  70.