diff options
author | stal <stal@zodiaclabs.org> | 2014-05-18 14:56:35 -0700 |
---|---|---|
committer | stal <stal@zodiaclabs.org> | 2014-05-18 14:56:35 -0700 |
commit | 28c5665a08a0e1862d5f4e880a9d094534a5a43c (patch) | |
tree | 49775e2000983b3c3018a0bda335b45c60ae12d1 | |
parent | 77d2ad373aa3fe3472a22e483a2ad6bed7e3fe5f (diff) |
Fix current_time_monotonic on OS X.
clock_gettime doesn't exist there, so
throw in some equivalent mach stuff.
-rw-r--r-- | toxcore/network.c | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/toxcore/network.c b/toxcore/network.c index 0505091d..2ffe067f 100644 --- a/toxcore/network.c +++ b/toxcore/network.c | |||
@@ -33,6 +33,12 @@ | |||
33 | #include <errno.h> | 33 | #include <errno.h> |
34 | #endif | 34 | #endif |
35 | 35 | ||
36 | #ifdef __APPLE__ | ||
37 | #include <mach/clock.h> | ||
38 | #include <mach/mach.h> | ||
39 | #endif | ||
40 | |||
41 | #include <sodium.h> | ||
36 | #include "network.h" | 42 | #include "network.h" |
37 | #include "util.h" | 43 | #include "util.h" |
38 | 44 | ||
@@ -229,6 +235,16 @@ uint64_t current_time_monotonic(void) | |||
229 | struct timespec monotime; | 235 | struct timespec monotime; |
230 | #if defined(__linux__) | 236 | #if defined(__linux__) |
231 | clock_gettime(CLOCK_MONOTONIC_RAW, &monotime); | 237 | clock_gettime(CLOCK_MONOTONIC_RAW, &monotime); |
238 | #elif defined(__APPLE__) | ||
239 | clock_serv_t muhclock; | ||
240 | mach_timespec_t machtime; | ||
241 | |||
242 | host_get_clock_service(mach_host_self(), SYSTEM_CLOCK, &muhclock); | ||
243 | clock_get_time(muhclock, &machtime); | ||
244 | mach_port_deallocate(mach_task_self(), muhclock); | ||
245 | |||
246 | monotime.tv_sec = machtime.tv_sec; | ||
247 | monotime.tv_nsec = machtime.tv_nsec; | ||
232 | #else | 248 | #else |
233 | clock_gettime(CLOCK_MONOTONIC, &monotime); | 249 | clock_gettime(CLOCK_MONOTONIC, &monotime); |
234 | #endif | 250 | #endif |