682269458904012c8f9d2d2ebc0604ad304e95ec
1 /********************* */
2 /*! \file clock_gettime.c
5 ** Major contributors: none
6 ** Minor contributors (to current version): none
7 ** This file is part of the CVC4 prototype.
8 ** Copyright (c) 2009, 2010 The Analysis of Computer Systems Group (ACSys)
9 ** Courant Institute of Mathematical Sciences
10 ** New York University
11 ** See the file COPYING in the top-level source directory for licensing
12 ** information.\endverbatim
14 ** \brief Replacement for clock_gettime() for systems without it (like
17 ** Replacement for clock_gettime() for systems without it (like Mac
25 #include "lib/clock_gettime.h"
29 #endif /* __cplusplus */
32 # warning This code assumes you're on Mac OS X, and you don't seem to be. You'll likely have problems.
33 #endif /* __APPLE__ */
35 #include <mach/mach_time.h>
37 static double s_clockconv = 0.0;
39 long clock_gettime(clockid_t which_clock, struct timespec *tp) {
40 if( s_clockconv == 0.0 ) {
41 mach_timebase_info_data_t tb;
42 kern_return_t err = mach_timebase_info(&tb);
44 s_clockconv = ((double) tb.numer) / tb.denom;
52 case CLOCK_REALTIME_HR:
54 case CLOCK_MONOTONIC_HR: {
55 uint64_t t = mach_absolute_time() * s_clockconv;
56 tp->tv_sec = t / 1000000000ul;
57 tp->tv_nsec = t % 1000000000ul;
69 #endif /* __cplusplus */