From: mquinson Date: Mon, 27 Jun 2005 22:11:12 +0000 (+0000) Subject: Use select to sleep portably on weird platforms X-Git-Tag: v3.3~3927 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/b98e7805e2b634992db0d8301ec0e13cf66b3c71?ds=inline Use select to sleep portably on weird platforms git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@1428 48e7efb5-ca39-0410-a469-dd3cf9ba447f --- diff --git a/src/gras/Virtu/rl_time.c b/src/gras/Virtu/rl_time.c index b7e6292dfc..49024d44e5 100644 --- a/src/gras/Virtu/rl_time.c +++ b/src/gras/Virtu/rl_time.c @@ -23,15 +23,20 @@ double gras_os_time() { } void gras_os_sleep(double sec) { - DEBUG1("Do sleep %d sec", (int)sec); - sleep(sec); - #ifdef HAVE_USLEEP - DEBUG1("Do sleep %d usec", (int) ((sec - floor(sec)) * 1000000 )); + DEBUG1("Do sleep %f sec", sec); + sleep(sec); (void)usleep( (sec - floor(sec)) * 1000000); -#else - if ( ((int) sec) == 0) { - WARN0("This platform does not implement usleep. Cannot sleep less than one second"); - } -#endif /* ! HAVE_USLEEP */ + +#else /* don't have usleep. Use select to sleep less than one second */ + struct timeval timeout; + + DEBUG1("Do sleep %f sec", sec); + + timeout.tv_sec = (unsigned long)(sec); + timeout.tv_usec = (sec - floor(sec)) * 1000000; + + select(0, NULL, NULL, NULL, &timeout); +#endif } +