1: /*
   2:  * Program: sleep.c
   3:  * Copyright: 1997, sms
   4:  * Author: Steven M. Schultz
   5:  *
   6:  * Version   Date	Modification
   7:  *     1.0  1997/9/26	1. Initial release.
   8: */
   9: 
  10: #include <stdio.h>  /* For NULL */
  11: #include <sys/types.h>
  12: #include <sys/time.h>
  13: 
  14: /*
  15:  * This implements the usleep(3) function using only 1 system call (select)
  16:  * instead of the 9 that the old implementation required.  Also this version
  17:  * avoids using signals (with the attendant system overhead).
  18:  *
  19:  * Nothing is returned and if less than ~20000 microseconds is specified the
  20:  * select will return without any delay at all.
  21: */
  22: 
  23: usleep(micros)
  24:     long micros;
  25:     {
  26:     struct timeval s;
  27: 
  28:     if  (micros > 0)
  29:         {
  30:         s.tv_sec = micros / 1000000L;
  31:         s.tv_usec = micros % 1000000L;
  32:         select(0, NULL, NULL, NULL, &s);
  33:         }
  34:     }
Last modified: 1997-09-26
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 2204
Valid CSS Valid XHTML 1.0 Strict