Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Use select to sleep portably on weird platforms
authormquinson <mquinson@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Mon, 27 Jun 2005 22:11:12 +0000 (22:11 +0000)
committermquinson <mquinson@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Mon, 27 Jun 2005 22:11:12 +0000 (22:11 +0000)
git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@1428 48e7efb5-ca39-0410-a469-dd3cf9ba447f

src/gras/Virtu/rl_time.c

index b7e6292..49024d4 100644 (file)
@@ -23,15 +23,20 @@ double gras_os_time() {
 }
  
 void gras_os_sleep(double sec) {
 }
  
 void gras_os_sleep(double sec) {
-  DEBUG1("Do sleep %d sec", (int)sec);
-  sleep(sec);
-
 #ifdef HAVE_USLEEP
 #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);
   (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
 }
 }
+