home *** CD-ROM | disk | FTP | other *** search
/ GEMini Atari / GEMini_Atari_CD-ROM_Walnut_Creek_December_1993.iso / zip / gnu / mntlib16.lzh / MNTLIB16 / SLEEP.C < prev    next >
C/C++ Source or Header  |  1993-07-29  |  1KB  |  54 lines

  1. /* sleep -- sleep for a specified number of seconds */
  2. /* usleep -- sleep for a specified number of microSecond */
  3. /* written by Eric R. Smith and placed in the public domain */
  4.  
  5. #include <time.h>
  6. #include <mintbind.h>
  7.  
  8. /* clock() has a rez of CLOCKS_PER_SEC ticks/sec */
  9.  
  10. #define USEC_PER_TICK (1000000U / ((unsigned long)CLOCKS_PER_SEC))
  11. #define    USEC_TO_CLOCK_TICKS(us)    ((us) / USEC_PER_TICK )
  12.  
  13. void
  14. sleep(n)
  15. unsigned int    n;
  16. {
  17.     unsigned long    stop;
  18.     extern int __mint;
  19.  
  20.     if (__mint) {
  21.         while (n > 32) {
  22.             (void)Fselect(32000, 0L, 0L, 0L);
  23.             n -= 32;
  24.         }
  25.         (void)Fselect(1000*n, 0L, 0L, 0L);
  26.     }
  27.     else {
  28.         stop = clock() + n * CLOCKS_PER_SEC;
  29.         while (clock() < stop)
  30.             ;
  31.     }
  32. }
  33.  
  34. /*
  35.  * Sleep for usec microSeconds 
  36.  * the actual suspension time can be arbitrarily longer
  37.  *
  38.  */
  39. void
  40. usleep(unsigned long usec)
  41. {
  42.     unsigned long    stop;
  43.     extern int __mint;
  44.  
  45.     if (__mint) {
  46.         (void)Fselect((unsigned)(usec/1000), 0L, 0L, 0L);
  47.     }
  48.     else {
  49.         stop = clock() + USEC_TO_CLOCK_TICKS(usec);
  50.         while (clock() < stop)
  51.             ;
  52.     }
  53. }
  54.