1 ////////////////////////////////////////////////////////////////////////////////
3 static struct timespec mclk_sttime
; // starting time of monotonic clock
9 #define CLOCK_REALTIME 0
10 #define CLOCK_MONOTONIC 1
11 #define CLOCK_PROCESS_CPUTIME_ID 2
12 #define CLOCK_THREAD_CPUTIME_ID 3
13 #define CLOCK_MONOTONIC_RAW 4
14 #define CLOCK_REALTIME_COARSE 5
15 #define CLOCK_MONOTONIC_COARSE 6
17 //clock_gettime is not implemented on OSX
18 // This implementation is found on the internet. Not sure if it's 100% correct
20 int clock_gettime(int clk_id
, struct timespec
* t
) {
22 int rv
= gettimeofday(&now
, NULL
);
24 t
->tv_sec
= now
.tv_sec
;
25 t
->tv_nsec
= now
.tv_usec
* 1000;
31 static void mclock_init (void) {
32 clock_gettime(CLOCK_MONOTONIC
/*CLOCK_MONOTONIC_RAW*/, &mclk_sttime
);
36 static K8TTimeMSec
mclock_ticks (void) {
39 clock_gettime(CLOCK_MONOTONIC
/*CLOCK_MONOTONIC_RAW*/, &tp
);
40 tp
.tv_sec
-= mclk_sttime
.tv_sec
;
41 return (K8TTimeMSec
)tp
.tv_sec
*1000+(tp
.tv_nsec
/1000000);