[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: gettimeofday() and clock



Steve Baker wrote:
> Chris Purnell wrote:
> 
>> On Mon, Sep 02, 2002 at 04:10:34PM -0500, Steve Baker wrote:
>>
>>> In what possible way could I change it to only give up one slice?
>>
>>
>> Use select() instead of usleep().

Wow!  It works!  Replacing the standard usleep with this
function gets the minimum sleep time down to 10ms.  So *WHY*
isn't the real usleep written like this??

   void my_usleep ( int us )
   {
     struct timeval tv ;
     fd_set empty ;

     tv.tv_sec  = us / 1000000 ;
     tv.tv_usec = us % 1000000 ;

     FD_ZERO ( &empty ) ;

     select ( 0, &empty, &empty, &empty, &tv ) ;
   }

...of course 10ms isn't nearly small enough for graphics applications - but
it's a *huge* improvement over 20ms.

----------------------------- Steve Baker -------------------------------
Mail : <sjbaker1@airmail.net>   WorkMail: <sjbaker@link.com>
URLs : http://www.sjbaker.org
        http://plib.sf.net http://tuxaqfh.sf.net http://tuxkart.sf.net
        http://prettypoly.sf.net http://freeglut.sf.net
        http://toobular.sf.net   http://lodestone.sf.net