home *** CD-ROM | disk | FTP | other *** search
/ Stone Design / Stone Design.iso / Stone_Friends / NeXT-Icons / next-icon@gun.com / Apps / ImagePortfolio / threads.subproj / sleepDelay.c < prev    next >
Encoding:
Text File  |  1993-06-03  |  1.1 KB  |  35 lines

  1. // -------------------------------------------------------------------------------------
  2. // thread safe sleep function
  3. // -------------------------------------------------------------------------------------
  4. // Permission is granted to freely redistribute this source code, and to use fragments
  5. // of this code in your own applications if you find them to be useful.  This module,
  6. // along with the source code, come with no warranty of any kind, and the user assumes
  7. // all responsibility for its use.
  8. // -------------------------------------------------------------------------------------
  9.  
  10. #import <stdio.h>
  11. #import <ctype.h>
  12. #import <libc.h>
  13. #import <sys/types.h>
  14. #import <sys/stat.h>
  15. #import <sys/param.h>
  16.  
  17. /* sleep for a number of seconds */
  18. int sleepDelay(float sec)
  19. {
  20.   u_long                uSec;
  21.   struct timeval        to;
  22.   fd_set                list;
  23.  
  24.   /* set up for 'select()' function */
  25.   FD_ZERO(&list);
  26.   FD_SET(1, &list);
  27.   uSec = (u_long)(sec * 1000000.0);
  28.   to.tv_sec  = uSec / 1000000L;
  29.   to.tv_usec = uSec % 1000000L;
  30.         
  31.   /* select call acts as delay */
  32.   return (select(1, &list, 0, 0, &to))? 0 : 1;
  33.         
  34. }
  35.