Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
49024d44e5147aa7c7623bdf1553d7cc15f9481d
[simgrid.git] / src / gras / Virtu / rl_time.c
1 /* $Id$ */
2
3 /* time - time related syscal wrappers                                      */
4
5 /* Copyright (c) 2003, 2004 Martin Quinson. All rights reserved.            */
6
7 /* This program is free software; you can redistribute it and/or modify it
8  * under the terms of the license (GNU LGPL) which comes with this package. */
9
10 #include "math.h" /* floor */
11
12 #include "portable.h"
13
14 #include "xbt/sysdep.h"
15 #include "gras/virtu.h"
16 #include "xbt/xbt_portability.h" /* private */
17
18 XBT_LOG_EXTERNAL_CATEGORY(virtu);
19 XBT_LOG_DEFAULT_CATEGORY(virtu);
20
21 double gras_os_time() {
22   return xbt_os_time();
23 }
24  
25 void gras_os_sleep(double sec) {
26 #ifdef HAVE_USLEEP
27   DEBUG1("Do sleep %f sec", sec);
28   sleep(sec);
29   (void)usleep( (sec - floor(sec)) * 1000000);
30         
31 #else /* don't have usleep. Use select to sleep less than one second */
32   struct timeval timeout;
33
34   DEBUG1("Do sleep %f sec", sec);
35   
36   timeout.tv_sec =  (unsigned long)(sec);
37   timeout.tv_usec = (sec - floor(sec)) * 1000000;
38               
39   select(0, NULL, NULL, NULL, &timeout);
40 #endif
41 }
42