ARGOBOTS  1.1
abtd_time.c
Go to the documentation of this file.
1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
2 /*
3  * See COPYRIGHT in top-level directory.
4  */
5 
6 #include "abti.h"
7 
8 #if defined(ABT_CONFIG_USE_MACH_ABSOLUTE_TIME)
9 static double g_time_mult = 0.0;
10 #endif
11 void ABTD_time_init(void)
12 {
13 #if defined(ABT_CONFIG_USE_MACH_ABSOLUTE_TIME)
14  mach_timebase_info_data_t info;
15  mach_timebase_info(&info);
16  g_time_mult = 1.0e-9 * ((double)info.numer / (double)info.denom);
17 #endif
18 }
19 
20 /* Obtain the time value */
21 void ABTD_time_get(ABTD_time *p_time)
22 {
23 #if defined(ABT_CONFIG_USE_CLOCK_GETTIME)
24  int ret = clock_gettime(CLOCK_REALTIME, p_time);
25  ABTI_ASSERT(ret == 0);
26 #elif defined(ABT_CONFIG_USE_MACH_ABSOLUTE_TIME)
27  *p_time = mach_absolute_time();
28 #elif defined(ABT_CONFIG_USE_GETTIMEOFDAY)
29  int ret = gettimeofday(p_time, NULL);
30  ABTI_ASSERT(ret == 0);
31 #endif
32 }
33 
34 /* Read the time value as seconds (double precision) */
35 double ABTD_time_read_sec(ABTD_time *p_time)
36 {
37  double secs;
38 
39 #if defined(ABT_CONFIG_USE_CLOCK_GETTIME)
40  secs = ((double)p_time->tv_sec) + 1.0e-9 * ((double)p_time->tv_nsec);
41 #elif defined(ABT_CONFIG_USE_MACH_ABSOLUTE_TIME)
42  if (g_time_mult == 0.0)
44  secs = *p_time * g_time_mult;
45 #elif defined(ABT_CONFIG_USE_GETTIMEOFDAY)
46  secs = ((double)p_time->tv_sec) + 1.0e-6 * ((double)p_time->tv_usec);
47 #endif
48 
49  return secs;
50 }
ABTD_time_read_sec
double ABTD_time_read_sec(ABTD_time *p_time)
Definition: abtd_time.c:35
ABTD_time_get
void ABTD_time_get(ABTD_time *p_time)
Definition: abtd_time.c:21
ABTD_time_init
void ABTD_time_init(void)
Definition: abtd_time.c:11
abti.h
ABTI_ASSERT
#define ABTI_ASSERT(cond)
Definition: abti_error.h:12