2 * Copyright (C) 2016 Michael Jeanson <mjeanson@efficios.com>
4 * SPDX-License-Identifier: MIT
17 typedef uint64_t timer_t;
19 #include <common/compat/errno.hpp>
21 #include <mach/clock.h>
22 #include <mach/mach.h>
29 #endif /* __APPLE__ */
31 /* macOS/OS X 10.12 (Sierra) and up provide clock_gettime() */
32 #if defined(__APPLE__) && !defined(LTTNG_HAVE_CLOCK_GETTIME)
34 typedef int clockid_t;
35 #define CLOCK_REALTIME CALENDAR_CLOCK
36 #define CLOCK_MONOTONIC SYSTEM_CLOCK
38 static inline int lttng_clock_gettime(clockid_t clk_id, struct timespec *tp)
44 if (clk_id != CLOCK_REALTIME && clk_id != CLOCK_MONOTONIC) {
50 host_get_clock_service(mach_host_self(), clk_id, &clock);
52 ret = clock_get_time(clock, &now);
53 if (ret != KERN_SUCCESS) {
58 tp->tv_sec = now.tv_sec;
59 tp->tv_nsec = now.tv_nsec;
62 mach_port_deallocate(mach_task_self(), clock);
67 #else /* __APPLE__ && !LTTNG_HAVE_CLOCK_GETTIME */
69 static inline int lttng_clock_gettime(clockid_t clk_id, struct timespec *tp)
71 return clock_gettime(clk_id, tp);
74 #endif /* __APPLE__ && !LTTNG_HAVE_CLOCK_GETTIME */
76 #endif /* _COMPAT_TIME_H */