ARGOBOTS
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 int ABTD_time_get(ABTD_time *p_time)
22 {
23  int abt_errno = ABT_SUCCESS;
24 
25 #if defined(ABT_CONFIG_USE_CLOCK_GETTIME)
26  clock_gettime(CLOCK_REALTIME, p_time);
27 #elif defined(ABT_CONFIG_USE_MACH_ABSOLUTE_TIME)
28  *p_time = mach_absolute_time();
29 #elif defined(ABT_CONFIG_USE_GETTIMEOFDAY)
30  gettimeofday(p_time, NULL);
31 #endif
32 
33  return abt_errno;
34 }
35 
36 /* Read the time value as seconds (double precision) */
37 double ABTD_time_read_sec(ABTD_time *p_time)
38 {
39  double secs;
40 
41 #if defined(ABT_CONFIG_USE_CLOCK_GETTIME)
42  secs = ((double)p_time->tv_sec) + 1.0e-9 * ((double)p_time->tv_nsec);
43 #elif defined(ABT_CONFIG_USE_MACH_ABSOLUTE_TIME)
44  if (g_time_mult == 0.0)
45  ABTD_time_init();
46  secs = *p_time * g_time_mult;
47 #elif defined(ABT_CONFIG_USE_GETTIMEOFDAY)
48  secs = ((double)p_time->tv_sec) + 1.0e-6 * ((double)p_time->tv_usec);
49 #endif
50 
51  return secs;
52 }
#define ABT_SUCCESS
Definition: abt.h:64