From: mquinson Date: Wed, 23 Feb 2005 13:57:53 +0000 (+0000) Subject: uniformize gras_os_sleep prototype (seconds are double everywhere else, avoid roundin... X-Git-Tag: v3.3~4302 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/97ba095764fbd852783e6a6dfe40da2fdd3f1f25 uniformize gras_os_sleep prototype (seconds are double everywhere else, avoid rounding errors) git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@1050 48e7efb5-ca39-0410-a469-dd3cf9ba447f --- diff --git a/examples/gras/ping/ping.c b/examples/gras/ping/ping.c index ea28d6896b..73c4c72b28 100644 --- a/examples/gras/ping/ping.c +++ b/examples/gras/ping/ping.c @@ -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))) { diff --git a/include/gras/virtu.h b/include/gras/virtu.h index 51939be681..e8c5faea4e 100644 --- a/include/gras/virtu.h +++ b/include/gras/virtu.h @@ -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 * diff --git a/src/gras/Virtu/rl_time.c b/src/gras/Virtu/rl_time.c index eeb782b2e9..e9d07b29e3 100644 --- a/src/gras/Virtu/rl_time.c +++ b/src/gras/Virtu/rl_time.c @@ -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 */ } diff --git a/src/gras/Virtu/sg_time.c b/src/gras/Virtu/sg_time.c index d83b25780e..ed80c7f9cf 100644 --- a/src/gras/Virtu/sg_time.c +++ b/src/gras/Virtu/sg_time.c @@ -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); }