home *** CD-ROM | disk | FTP | other *** search
/ PC Extra Super CD 1998 January / PCPLUS131.iso / DJGPP / V2 / DJLSR201.ZIP / src / libc / compat / unistd / usleep.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-07-21  |  557 b   |  26 lines

  1. /* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
  2. #include <unistd.h>
  3. #include <time.h>
  4. #include <dpmi.h>
  5.  
  6. unsigned int
  7. usleep(unsigned int _useconds)
  8. {
  9.   clock_t cl_time;
  10.   clock_t start_time = clock();
  11.  
  12.   /* 977 * 1024 is about 1e6.  The funny logic keeps the math from
  13.      overflowing for large _useconds */
  14.   _useconds >>= 10;
  15.   cl_time = _useconds * CLOCKS_PER_SEC / 977;
  16.  
  17.   while (1)
  18.   {
  19.     clock_t elapsed = clock() - start_time;
  20.     if (elapsed >= cl_time)
  21.       break;
  22.     __dpmi_yield();
  23.   }
  24.   return 0;
  25. }
  26.