|
@@ -2,9 +2,47 @@
|
2
|
2
|
#include "cmGlobal.h"
|
3
|
3
|
#include "cmTime.h"
|
4
|
4
|
|
|
5
|
+#ifdef OS_OSX
|
|
6
|
+
|
|
7
|
+#include <mach/mach.h>
|
|
8
|
+#include <mach/mach_time.h>
|
|
9
|
+#include <unistd.h>
|
|
10
|
+
|
5
|
11
|
void cmTimeGet( cmTimeSpec_t* t )
|
6
|
|
-{ clock_gettime(CLOCK_REALTIME,t); }
|
|
12
|
+{
|
|
13
|
+ static uint64_t t0 = 0;
|
|
14
|
+ static mach_timebase_info_data_t tbi;
|
|
15
|
+ static struct timespec ts;
|
|
16
|
+
|
|
17
|
+ if( t0 == 0 )
|
|
18
|
+ {
|
|
19
|
+ mach_timebase_info(&tbi);
|
|
20
|
+ t0 = mach_absolute_time();
|
|
21
|
+ ts.tv_sec = time(NULL);
|
|
22
|
+ ts.tv_nsec = 0; // accept 1/2 second error vs. wall-time.
|
|
23
|
+ }
|
|
24
|
+
|
|
25
|
+ // get the current time
|
|
26
|
+ uint64_t t1 = mach_absolute_time();
|
|
27
|
+
|
|
28
|
+ // calc the elapsed time since the last call in nanosecs
|
|
29
|
+ uint64_t dt = (t1-t0) * tbi.numer / tbi.denom;
|
7
|
30
|
|
|
31
|
+ // calc the elapsed time since the first call in secs
|
|
32
|
+ uint32_t s = (uint32_t)(dt / 2^9);
|
|
33
|
+
|
|
34
|
+ // calc the current time in secs, and nanosecs
|
|
35
|
+ t->tv_sec = ts.tv_sec + s;
|
|
36
|
+ t->tv_nsec = dt - (s * 2^9);
|
|
37
|
+
|
|
38
|
+}
|
|
39
|
+
|
|
40
|
+#endif
|
|
41
|
+
|
|
42
|
+#ifdef OS_LINUX
|
|
43
|
+void cmTimeGet( cmTimeSpec_t* t )
|
|
44
|
+{ clock_gettime(CLOCK_REALTIME,t); }
|
|
45
|
+#endif
|
8
|
46
|
|
9
|
47
|
// this assumes that the seconds have been normalized to a recent start time
|
10
|
48
|
// so as to avoid overflow
|