home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c070 / 4.ddi / TOOLS.4 / TCTSRC1.EXE / UTSLEEP.C < prev    next >
Encoding:
C/C++ Source or Header  |  1989-03-31  |  1.7 KB  |  67 lines

  1. /**
  2. *
  3. * Name        UTSLEEP -- Suspend processing for some duration.
  4. *
  5. * Synopsis    rdur = utsleep(period);
  6. *
  7. *        unsigned rdur      The number of timer ticks the process
  8. *                  was actually suspended.
  9. *        unsigned period   The number of timer ticks the process
  10. *                  is to be suspended.
  11. *
  12. * Description    UTSLEEP suspends processing for at least the number of
  13. *        ticks requested, and returns the actual number as the
  14. *        functional value.  Because the function checks the
  15. *        system clock to determine if the period has transpired,
  16. *        it is possible that the actual duration is longer than
  17. *        requested.
  18. *
  19. *        On standard IBM PCs, timer ticks occur 1193180/65536
  20. *        (about 18.2) times per second.
  21. *
  22. *        This function temporarily enables hardware interrupts
  23. *        but restores the state of the interrupt flag before it
  24. *        returns.
  25. *
  26. * Returns    rdur          The number of timer ticks the
  27. *                  process actually slept.
  28. *
  29. * Version    6.00 (C)Copyright Blaise Computing Inc.  1984,1987,1989
  30. *
  31. **/
  32.  
  33.  
  34. #include <butil.h>
  35.  
  36.  
  37. unsigned utsleep(period)
  38. unsigned period;
  39. {
  40.     long     initclk;        /* Initial clock count.         */
  41.     long     nowclk;        /* Moving clock count.            */
  42.     unsigned elpticks;        /* Elapsed tick count.            */
  43.     int      ints_were_on;    /* Whether interrupts were on        */
  44.                 /* already.                */
  45.  
  46.     /* Find out the current clock count and wait until period        */
  47.     /* counts have passed.                        */
  48.  
  49.     ints_were_on = utinton();
  50.  
  51.     utgetclk(&initclk);
  52.  
  53.     for (elpticks = 0;
  54.      elpticks < period;
  55.      elpticks = (unsigned) (nowclk - initclk))
  56.     {
  57.     utgetclk(&nowclk);
  58.     if (nowclk < initclk)    /* Must have wrapped past midnight. */
  59.         nowclk += 0x1800b0L;
  60.     }
  61.  
  62.     if (!ints_were_on)
  63.     utintoff();
  64.  
  65.     return(elpticks);
  66. }
  67.