3 /* time - time related syscal wrappers */
5 /* Copyright (c) 2003, 2004 Martin Quinson. All rights reserved. */
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. */
10 #include <math.h> /* floor */
14 #include "xbt/sysdep.h"
16 #include "gras/virtu.h"
17 #include "xbt/xbt_portability.h" /* private */
19 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(gras_virtu);
21 double gras_os_time() {
25 void gras_os_sleep(double sec) {
27 DEBUG1("Do sleep %f sec", sec);
29 (void)usleep( (sec - floor(sec)) * 1000000);
32 DEBUG1("Do sleep %f sec", sec);
34 Sleep((floor(sec) * 1000) +((sec - floor(sec)) * 1000));
37 #else /* don't have usleep. Use select to sleep less than one second */
38 struct timeval timeout;
40 DEBUG1("Do sleep %f sec", sec);
42 timeout.tv_sec = (unsigned long)(sec);
43 timeout.tv_usec = (sec - floor(sec)) * 1000000;
45 select(0, NULL, NULL, NULL, &timeout);