1 /********************* */
2 /*! \file clock_gettime.c
4 ** Top contributors (to current version):
5 ** Morgan Deters, Tim King, Paul Meng
6 ** This file is part of the CVC4 project.
7 ** Copyright (c) 2009-2018 by the authors listed in the file AUTHORS
8 ** in the top-level source directory) and their institutional affiliations.
9 ** All rights reserved. See the file COPYING in the top-level source
10 ** directory for licensing information.\endverbatim
12 ** \brief Replacement for clock_gettime() for systems without it (like
15 ** Replacement for clock_gettime() for systems without it (like Mac
19 // #warning "TODO(taking): Make lib/clock_gettime.h cvc4_private.h again."
21 #include "lib/clock_gettime.h"
25 #endif /* __cplusplus */
31 #include <mach/mach_time.h>
33 static double s_clockconv
= 0.0;
35 long clock_gettime(clockid_t which_clock
, struct timespec
* tp
) {
36 if( s_clockconv
== 0.0 ) {
37 mach_timebase_info_data_t tb
;
38 kern_return_t err
= mach_timebase_info(&tb
);
40 s_clockconv
= ((double) tb
.numer
) / tb
.denom
;
48 case CLOCK_REALTIME_HR
:
50 case CLOCK_MONOTONIC_HR
: {
51 uint64_t t
= mach_absolute_time() * s_clockconv
;
52 tp
->tv_sec
= t
/ 1000000000ul;
53 tp
->tv_nsec
= t
% 1000000000ul;
63 #else /* not defined __APPLE__ */
69 long clock_gettime(clockid_t which_clock
, struct timespec
* tp
) {
72 GetSystemTimeAsFileTime(&ft
);
73 uint64_t nanos
= ((((uint64_t)ft
.dwHighDateTime
) << 32) | ft
.dwLowDateTime
) * 100;
74 tp
->tv_sec
= nanos
/ 1000000000ul;
75 tp
->tv_nsec
= nanos
% 1000000000ul;
80 #endif /* closing #ifdef __WIN32__ */
81 #endif /* closing #else for #ifdef __APPLE__ / __WIN32__ */
85 #endif /* __cplusplus */