|
@@ -157,9 +157,25 @@ int decode_hex_string(char *hex, uint8_t *bin, int asc_len) {
|
157
|
157
|
return asc_len / 2;
|
158
|
158
|
}
|
159
|
159
|
|
|
160
|
+#ifdef __MACH__
|
|
161
|
+#include <mach/clock.h>
|
|
162
|
+#include <mach/mach.h>
|
|
163
|
+#endif
|
|
164
|
+
|
160
|
165
|
int64_t get_time(void) {
|
161
|
166
|
struct timespec ts;
|
|
167
|
+#ifdef __MACH__
|
|
168
|
+// OS X does not have clock_gettime, use clock_get_time
|
|
169
|
+ clock_serv_t cclock;
|
|
170
|
+ mach_timespec_t mts;
|
|
171
|
+ host_get_clock_service(mach_host_self(), CALENDAR_CLOCK, &cclock);
|
|
172
|
+ clock_get_time(cclock, &mts);
|
|
173
|
+ mach_port_deallocate(mach_task_self(), cclock);
|
|
174
|
+ ts.tv_sec = mts.tv_sec;
|
|
175
|
+ ts.tv_nsec = mts.tv_nsec;
|
|
176
|
+#else
|
162
|
177
|
if (clock_gettime(CLOCK_MONOTONIC, &ts) == EINVAL) // Shouldn't happen on modern Linux
|
163
|
178
|
clock_gettime(CLOCK_REALTIME, &ts);
|
|
179
|
+#endif
|
164
|
180
|
return ts.tv_sec * 1000000ll + ts.tv_nsec / 1000;
|
165
|
181
|
}
|