From 48fb61a024cd614fd1544b95c360022fc470b505 Mon Sep 17 00:00:00 2001 From: alegrand Date: Thu, 31 Mar 2005 01:21:58 +0000 Subject: [PATCH] Add xbt_os_time(). This functions returns the number of seconds since the Epoch (00:00:00 UTC, January 1, 1970). Most users should use gras_os_time and should not use this function unless they really know what they are doing. git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@1200 48e7efb5-ca39-0410-a469-dd3cf9ba447f --- include/xbt/sysdep.h | 7 +++++++ src/xbt/sysdep.c | 19 ++++++++++++++++--- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/include/xbt/sysdep.h b/include/xbt/sysdep.h index b405a7afd2..4bd3cea284 100644 --- a/include/xbt/sysdep.h +++ b/include/xbt/sysdep.h @@ -91,6 +91,13 @@ static inline void *xbt_realloc(void*p,int s){ /** @} */ +/** @brief get time in seconds + + * gives the number of seconds since the Epoch (00:00:00 UTC, January 1, 1970). + * Most users should use gras_os_time and should not use this function unless + they really know what they are doing. */ +double xbt_os_time(void); + END_DECL() #endif /* _XBT_SYSDEP_H */ diff --git a/src/xbt/sysdep.c b/src/xbt/sysdep.c index a3b0a8a040..428d006728 100644 --- a/src/xbt/sysdep.c +++ b/src/xbt/sysdep.c @@ -1,6 +1,6 @@ /* $Id$ */ -/* sysdep.h -- all system dependency */ +/* sysdep.c -- all system dependency */ /* no system header should be loaded out of this file so that we have only */ /* one file to check when porting to another OS */ @@ -12,13 +12,26 @@ #include "xbt/sysdep.h" #include "xbt/log.h" #include "xbt/error.h" - -#include +#include "portable.h" /* \defgroup XBT_sysdep All system dependency * \brief This section describes many macros/functions that can serve as * an OS abstraction. */ +double xbt_os_time(void) { +#ifdef HAVE_GETTIMEOFDAY + struct timeval tv; + + gettimeofday(&tv, NULL); + + return (double)(tv.tv_sec + tv.tv_usec / 1000000.0); +#else + /* Poor resolution */ + return (double)(time(NULL)); +#endif /* HAVE_GETTIMEOFDAY? */ +} + + XBT_LOG_NEW_DEFAULT_SUBCATEGORY(sysdep, xbt, "System dependency"); -- 2.20.1