-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathplatform.h
34 lines (30 loc) · 908 Bytes
/
platform.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
//File for platform specific functions
// Add others as needed
//
// (c) 2014 Adam Shelly (github.com/ashelly)
#include <time.h>
typedef struct timespec sysTime_t;
#define MS_PER_SEC 1000.0f
//** Linux specific high-precision timing**/
//returns elapsed time between `now` and `then` as sysType_t
static inline sysTime_t platformTimeElapsed(sysTime_t now, sysTime_t then)
{
sysTime_t e;
e.tv_sec = now.tv_sec-then.tv_sec;
if (now.tv_nsec < then.tv_nsec){
e.tv_sec-=1;
e.tv_nsec = now.tv_nsec+(1e9-then.tv_nsec);
}
else{
e.tv_nsec = now.tv_nsec-then.tv_nsec;
}
return e;
}
//converts `timeIn` to Milliseconds
static inline double platformSysTimeToMs(sysTime_t timeIn) {
return (double)timeIn.tv_sec* MS_PER_SEC + (double)timeIn.tv_nsec / 1e6;
}
//fills `out` with current time
static inline void platformGetTime(sysTime_t* out){
clock_gettime(CLOCK_THREAD_CPUTIME_ID, out);
}