Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
uniformize gras_os_sleep prototype (seconds are double everywhere else, avoid roundin...
authormquinson <mquinson@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Wed, 23 Feb 2005 13:57:53 +0000 (13:57 +0000)
committermquinson <mquinson@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Wed, 23 Feb 2005 13:57:53 +0000 (13:57 +0000)
git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@1050 48e7efb5-ca39-0410-a469-dd3cf9ba447f

examples/gras/ping/ping.c
include/gras/virtu.h
src/gras/Virtu/rl_time.c
src/gras/Virtu/sg_time.c

index ea28d68..73c4c72 100644 (file)
@@ -119,7 +119,7 @@ int server (int argc,char *argv[]) {
   
   /* 8. Sleep one second, but only in real life, not in simulation */
   if (!gras_if_RL())
-    gras_os_sleep(1, 0);
+    gras_os_sleep(1);
 
   /* 9. Free the allocated resources, and shut GRAS down */
   gras_socket_close(globals->sock);
@@ -158,7 +158,7 @@ int client(int argc,char *argv[]) {
   INFO2("Launch client (server on %s:%d)",host,port);
    
   /* 3. Wait for the server startup */
-  gras_os_sleep(1,0);
+  gras_os_sleep(1);
    
   /* 4. Create a socket to speak to the server */
   if ((errcode=gras_socket_client(host,port,&toserver))) {
index 51939be..e8c5fae 100644 (file)
@@ -27,9 +27,8 @@ double gras_os_time(void);
 
 /** @brief sleeps for the given amount of time.
  *  @param sec: number of seconds to sleep
- *  @param usec: number of microseconds to sleep
  */
-void gras_os_sleep(unsigned long sec, unsigned long usec);
+void gras_os_sleep(double sec);
 
 /** @brief get the fully-qualified name of the current host
  *
index eeb782b..e9d07b2 100644 (file)
@@ -7,11 +7,15 @@
 /* This program is free software; you can redistribute it and/or modify it
  * under the terms of the license (GNU LGPL) which comes with this package. */
 
+#include "math.h" /* floor */
+
 #include "portable.h"
 
 #include "xbt/sysdep.h"
 #include "gras/virtu.h"
 
+XBT_LOG_EXTERNAL_CATEGORY(virtu);
+XBT_LOG_DEFAULT_CATEGORY(virtu);
 
 double gras_os_time() {
 #ifdef HAVE_GETTIMEOFDAY
@@ -27,11 +31,16 @@ double gras_os_time() {
        
 }
  
-void gras_os_sleep(unsigned long sec,unsigned long usec) {
+void gras_os_sleep(double sec) {
+  DEBUG1("Do sleep %d sec", (int)sec);
   sleep(sec);
-  if (usec/1000000) sleep(usec/1000000);
 
 #ifdef HAVE_USLEEP
-  (void)usleep(usec % 1000000);
+  DEBUG1("Do sleep %d usec", (int) ((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 */
 }
index d83b257..ed80c7f 100644 (file)
@@ -19,6 +19,6 @@ double gras_os_time() {
 /*
  * Freeze the process for the specified amount of time
  */
-void gras_os_sleep(unsigned long sec,unsigned long usec) {
-  MSG_process_sleep((double)sec + ((double)usec)/1000000);
+void gras_os_sleep(double sec) {
+  MSG_process_sleep(sec);
 }